androidgeolocationgeofencing

Android Geofence Automatically removed when location service is disabled / restarted


I have successfully added the geofence with the Flag NEVER_EXPIRE. And everything seems to be working fine.

But now while testing i found that if i stop the location services geofence stops working as EXPECTED. Further when i start the location services again my previously added geofence should again start working but no notifications are generated and it seems the geofence are automatically removed once the location services is disabled . And i have to again set all the locations to get back the geofence in working state.

Any suggestions or any idea why it behaves this way??

EDIT::

Similar Issue is also seen when the Device is Turned off / Restarted etc. So basically all the geofences which are registered will be expired if Location Services is disabled / Device is restarted . Few of which i tried to handle by Session but i am looking for a solution by which we can set the Geofences back when the location service is enabled .


Solution

  • Found this Answer::: http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html

    In case network location provider is disabled by the user, the geofence service will stop updating, all registered geofences will be removed and an intent is generated by the provided pending intent. In this case, hasError(Intent) returns true and getErrorCode(Intent) returns GEOFENCE_NOT_AVAILABLE.

    Now:::: How can we register the geofence back when the location service is back.. (IN BACKGROUND)