Reputation: 634
I'm currently developing an app that requires the Android's location service to always be active.
Right now I'm able to detect if the user activates or deactivates the location service when he resumes the app (in the onResume() event ).
The problem is that, if the user deactivates the location service throught the quick settings menu, I am not able to detect the event.
How can I know when the user activates / deactivates the device's location through the quick settings?
Thank you.
My code:
...
BroadcastReceiver mGpsSwitchStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
// Make an action or refresh an already managed state.
Log.d("vtApp", "CHANGED");
}
}
};
currentActivity.registerReceiver(mGpsSwitchStateReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
References I followed:
How to trigger broadcast receiver when gps is turn on/off?
Android Quick Settings notifications?
Upvotes: 2
Views: 438
Reputation: 110
I had the same problem. this worked for me
intentFilter.addAction(android.location.LocationManager.PROVIDERS_CHANGED_ACTION);
not to confuse it with
Intent.ACTION_PROVIDER_CHANGED
Upvotes: 3