Code: Select all
fun setupMockLocationApp() {
val packageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName
val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation
uiAutomation.executeShellCommand("appops set $packageName android:mock_location allow")
}
fun setMockLocationFused(lat: Double, lng: Double, accuracy: Float = 3F) {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context)
Tasks.await(fusedLocationClient.setMockMode(true))
val location = Location(LocationManager.GPS_PROVIDER).apply {
this.latitude = lat
this.longitude = lng
this.accuracy = accuracy
this.time = System.currentTimeMillis()
}
Tasks.await(fusedLocationClient.setMockLocation(location))
}
Code: Select all
@Before
fun setUp() {
setupMockLocationApp()
setMockLocationFused(lat, lng)
}
Was könnte dieses Problem verursachen und wie kann ich das sicherstellen? dass der simulierte Standort in Google Maps angezeigt wird?