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
Thanks to @usman 's answer we can apply the solution without extends
the class by the following way;
AndroidManifest.xml;
class (I never tested);
public class LocationProviderChangedReceiver {
private mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String ability = (isGPSProviderEnabled() && isNetworkProviderEnabled()) ? "CAN" : "CANNOT";
Log.d("", "The location " + ability + " be caught in high accuracy!");
}
};
public startProviderChangeObserving () {
registerReceiver(mReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
}
public stopProviderChangeObserving () {
unregisterReceiver(mReceiver);
}
/**
* Method to verify that the location providers wheter on or not on the device
**/
public boolean isGPSProviderEnabled() {
return (Boolean) mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
public boolean isNetworkProviderEnabled() {
return (Boolean) mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}
}