6

According to the Android geofencing documentation one should re-register the geofences if the following cases occur:

  • The device is rebooted.

Solution: The app should store the geofences internally (SharedPreferences) when the geofence is added. Then listen for the device's boot complete action, and re-register the stored geofences.

  • The app is uninstalled and re-installed.

Solution: User should create the geofences again or store them remotely and then retrieve when the app opens for the first time.

  • The app's data is cleared.

Solution: User should create the geofences again or store them remotely and then retrieve when the app opens for the first time.


However, I don't know what to do in the following cases, please can you advice?

  • Google Play services data is cleared. How can I detect this case?

  • The app has received a GEOFENCE_NOT_AVAILABLE alert. This typically happens after NLP (Android's Network Location Provider) is disabled. Not sure where this 'alert' is received

fernandospr
  • 2,976
  • 2
  • 22
  • 43
  • Not sure where this 'alert' is received: It will be in you Service, where you will receive Transitions. Youcan check that using: GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); if(geofencingEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) – Sagar Jun 30 '16 at 23:21
  • Please see [my answer to a similar question](https://stackoverflow.com/a/50869301/766755) as I believe it should cover all the cases where you should re-register geofences based on the documentation. – Michael Krause Jul 26 '18 at 21:12

1 Answers1

0

I found no way of detecting the case of Google Play services data is cleared, so I just request for new geofences whenever the app is opened.

As @Sagar mentioned, GEOFENCE_NOT_AVAILABLE is received in the transitions service. This is received when the Location is disabled. To workaround this, I save the geofences (using SharedPreferences) whenever I request them, and then I have a BroadcastReceiver that detects when the Location is enabled again. I reload the saved geofences here.

Thanks.

fernandospr
  • 2,976
  • 2
  • 22
  • 43
  • LocationManager.PROVIDERS_CHANGED_ACTION will not work on API 26 and higher - What will you do now? :- https://stackoverflow.com/questions/48659124/locationmanager-providers-changed-action-will-not-work-on-api-26-and-higher – Gunaseelan Feb 13 '18 at 08:14