I wish to receive a notification when the user enables or disables either Network or GPS locations, and importantly I wish to know which one they have changed and how. I have a
This works for me:
Add receiver to the Manifest file:
Check both location providers in receiver:
public class LocationProviderChangedReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
boolean anyLocationProv = false;
LocationManager locationManager = (LocationManager) MyMainActivity.context.getSystemService(Context.LOCATION_SERVICE);
anyLocationProv |= locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
anyLocationProv |= locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.i("", "Location service status" + anyLocationProv);
}
}
Though this receiver is called more than once due to obvious reasons, but this will tell you the status.