0

I'm doing testing with Google's location services sample, namely the geofence sample. https://github.com/android/location-samples/tree/master/Geofencing

As I understand it there should be a geofence event on location being turned off by the user so I can handle the status GEOFENCE_NOT_AVAILABLE but I'm not getting any event on location setting being turned off and I dont see any errors in general. How can i get an event when location is turned off

geoxile
  • 348
  • 1
  • 6
  • 16

1 Answers1

0

Using the sample, you should be able to intercept the status code in GeofenceBroadcastReceiver.java.

public class GeofenceBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        GeofencingEvent event = GeofencingEvent.fromIntent(intent)
        if ( event.hasError() && event.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE ) { ... }
    }
}

check out the below link for GeofencingEvent.getErrorCode() in case you are still unsure. https://developers.google.com/android/reference/com/google/android/gms/location/GeofencingEvent.html#getErrorCode()

Dat Pham Tat
  • 1,433
  • 7
  • 9
  • 1
    I'm just debugging it with the sample in foreground. Problem is there is no broadcast received when I turn off the location setting manually. I get on and dwell as well as exit but nothing when I turn the location setting off. – geoxile Nov 05 '19 at 21:57
  • 1
    According to documentation, on most devices, the geofence service uses only network location for geofence triggering, so maybe try turning off network as well, otherwise I have no ideas left, sorry. Maybe check out this thread, might be the same as your problem: https://stackoverflow.com/questions/57413993/geofence-problem-in-triggering-geofence-not-available – Dat Pham Tat Nov 05 '19 at 23:08