Open Dmitry-Komarovsky opened 3 years ago
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:
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: