According to the Android geofencing documentation one should re-register the geofences if the following cases occur:
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.
Solution: User should create the geofences again or store them remotely and then retrieve when the app opens for the first time.
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
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.