Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geofences randomly fail to trigger until another GPS app is opened

I have been testing an app for many months which uses the Android Geofencing API to track enter/exit events. It works flawlessly about 99% of the time, but there are random times when the geofences simply do not trigger.

This cannot be an issue caused by my application failing to keep the geofences loaded, because whenever the fences fail to trigger, opening a completely separate GPS application, ie google maps, immediately causes my application to trigger the geofence event that it had failed to.

  • I am handling the reloading of the fences through a broadcast receiver on BOOT_COMPLETED and location.PROVIDER_CHANGED.
  • The fence radius is reasonably large, over 1 mile.
  • The app is not being put to sleep or under power management.
  • Users and personal testing show this is never due to location services being disabled manually.
  • There is no dwell and the fences never expire.

As I said, the geofences work flawlessly 99% of the time, and the other 1% simply opening another gps application immediately triggers the fences. I'm trying to figure out what I can do to eliminate the failing 1%, hopefully something short of constantly polling location (which makes the geofencing api pointless anyway).

Update: (Limited testing sample size of 1)On a device running Android Oreo, this issue seems to have become exacerbated to the point of geofences never triggering unless a secondary gps app is launched...

like image 984
RB2017 Avatar asked Jul 10 '18 12:07

RB2017


1 Answers

I don't know if this will help anybody but with the Background limitations starting from Android O the geofences work as you described, only opening apps that get the current location of the user will trigger the geofences.

You can create a Foreground service and poll the location from the Fused Location Provider in order to make Geofences to actually work.

I hope someone else found a better solution.

like image 97
Rogelio Robledo Avatar answered Nov 13 '22 15:11

Rogelio Robledo