android / location-samples

Multiple samples showing the best practices in location APIs on Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LocationUpdates app can't detect location on device with Android 10 when running with any fake GPS app to mock location

Dmitry-Komarovsky opened this issue · comments

When I press 'START UPDATES' button in LocationUpdates app while running it with any fake GPS app on device with Android 10, I get the following exception:

11-24 19:23:18.876: I/MainActivity(31143): com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source:3)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.common.internal.zai.zaf(Unknown Source:2)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.common.internal.zaj.onComplete(Unknown Source:6)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.common.api.internal.BasePendingResult.zaa(Unknown Source:172)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source:131)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.common.api.internal.BaseImplementation$ApiMethodImpl.setResult(Unknown Source:36)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.internal.location.zzbc.zza(Unknown Source:2)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.internal.location.zzar.dispatchTransaction(Unknown Source:11)
11-24 19:23:18.876: I/MainActivity(31143): 	at com.google.android.gms.internal.location.zzb.onTransact(Unknown Source:22)
11-24 19:23:18.876: I/MainActivity(31143): 	at android.os.Binder.execTransactInternal(Binder.java:1021)
11-24 19:23:18.876: I/MainActivity(31143): 	at android.os.Binder.execTransact(Binder.java:994)

I've been finding the same problem. I can't get geofences to trigger with latest Android 11. I haven't tried any other versions. It's very frustrating. Looking at the code for this project it looks outdated but even following the latest Android code recommendations on their website I've not been able to get any Geofences to trigger using the latest Android Studio build emulator.

did you guys find any workaround?

did you guys find any workaround?

No. It seems the Android emulator has an issue with triggering notifications. Or it does on my machine anyway! It doesn’t work unless you open the maps app. As soon as you do the notifications trigger.
I can confirm the same code runs perfectly well when running on an actual device.
I spent quite a few hours thinking my code was at fault. I even tried different Android api’s 26,28,29 and 30. All had the same problem.

i have this issue on real devices too. i can confirm that running google maps works as a temporary solution

i have this issue on real devices too. i can confirm that running google maps works as a temporary solution

So you’re saying that you have to open the maps app on actual device in order for notification go fire?

to be precise: this hack doesn't work for real device :( (at least mine xiaomi redmi 9)
but I came to it intuitively when used an emulator. and it worked for me.

i have this issue on real devices too. i can confirm that running google maps works as a temporary solution

IMHO this is broken, a GeoFenceBroadCast Receiver should be all that's necessary, but apparently it doesn't work unless some service is asking the system for location updates. This happens both when you run google maps and when you start a ForeGround location service that has access to real time updates. So what I did was start a service that is looking for Fine location accuracy.
See also:
https://stackoverflow.com/questions/54348093/geofencing-in-background-on-android-8-or-9-does-not-work/69692654#69692654

I linked the google location-samples foreground service example in that stackOverFlow link. Basically I am doing nothing with the location updates received by the service, since I already have a GeoFenceBroadcastReciever registered. Previously, my geoFences would never get triggered on entry/exit. With the service I am able to now get the location updates timely enough that they trigger my geoFences. Without this foreGround location service the alternative is to run google maps. BTW, this behavior presents itself in both the Emulator and on a real device.

Not sure if there's a better solution out there, I wish there was, as technically running a service just to get prompt triggering of geoFence broadCasts really stinks.

BTW, here's my dirty dirty (but working) code:

https://github.com/Lcstyle/LazyBoneBLE/blob/master/app/src/main/java/com/tinysine/lazyboneble/geolocation/BackgroundGeoFenceLocationService.java