I'm trying to register a BroadcastReceiver
for get the state changes of Location
settings
But I didn't find any documentation for doing it. I only found BroadcastReceiver
to check the status of certain search providers (GPS
and Network providers
); but not for checking if this particular option (Location
) is active or not in the system preferences.
Somebody can show me the right direction?
NOTE:
I used Google Play Location Service (
com.google.android.gms.location.LocationListener
interface).
Well, I found one way to check if the "Location
" setting of the action bar
is enabled or disabled; but without a BroadcastReceiver
(a shame, really)
private static final String TAG = getClass().getName();
/* We define the LocationManager */
LocationManager location_Manager= (LocationManager) getSystemService(LOCATION_SERVICE);
/* If the GPS provider or the network provider are enabled; the Location setting is enabled.*/
if(location_Manager.isProviderEnabled(LocationManager.GPS_PROVIDER) || location_Manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
Log.d(TAG, "The Location setting is enabled");
}else{
/* We send the user to the "Location activity" to enable the setting */
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
I really did not need a BroadcastReceiver
; since the "arquitecture" that has my app allows me to do without it; but I would have liked to know how to use it.
NOTICE:
If someone finds the way to make it with a
BroadcastReceiver
I will change my correct answer by her answer.