I'm working on a library that can be used to monitor geofences on Android devices. I've noticed that the geofences I register with Google Play Location Services GeofencingApi class are lost after I turn Location Services off and back on in the device settings.
I have seen folks suggesting that I need to register for the android.location.PROVIDERS_CHANGED
broadcast receiver in my AndroidManifest.xml
file. I've done that -- but this broadcast receiver only gets called when I add and remove test providers in my test application. I don't receive it at all when toggling Location Services in the device settings.
Am I doing something wrong? Does anyone know how to reliably determine when the user toggles Location Services in the device settings? I'd like to be able to see these events in the background -- even if my app is not running.
I figure I could set up an repeating task that runs in the background and periodically checks to see if Location Services has been toggled, but it sounds gross and inefficient.
If it helps, I'm testing on an Moto G running Android 4.4.2. Everything I have done with geofences has worked fine until now.
EDIT: After doing more research I have found that the behaviour of the PROVIDERS_CHANGED
broadcast is highly variable depending on phone version and model. My Nexus 5 running Android 5.1 seems to work fine actually - I am able to get the PROVIDERS_CHANGED
broadcast very regularly. I also have a Moto G and Moto X phone running 4.4.x and they never produced the PROVIDERS_CHANGED
broadcast for me. A Samsung Galaxy S3 on Android 4.2 would produce the broadcast for me but stop doing it after I used my Map Activity with test location providers.
Anyways, I have decide to stop pursuing this problem for now. I think Android is just being buggy.