title: Is it possible to get a notification when any location provider is enabled/disabled and ascertain what action occurred?
body: <p>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 broadcast receiver for the <code>android.location.PROVIDERS_CHANGED</code> broadcast intent and this is receiving the correct broadcast. </p>
  
  <p>I now need to try and determine which action has occurred i.e. enable or disable and which provider has been changed. I know that I could keep the state of each provider and then when I receive notification that they have changed then I could work out what has changed, I am looking for a more "standard" method of doing this. The broadcast intent does not seem to have any extras to indicate which provider has changed.</p>
  
  <p>This is the code I have currently.</p>
  
  <pre><code>    public class LocationProviderChangedReceiver extends BroadcastReceiver {
      private final static String TAG = "LocationProviderChangedReceiver";
  
      @Override
      public void onReceive(Context context, Intent intent) {
        if (intent.getAction().matches("android.location.PROVIDERS_CHANGED"))
        {
          Log.i(TAG,"Location Providers changed");
          Bundle bundle = intent.getExtras();
          if (bundle == null) {
            Log.d(TAG, "No extras data");
           } else {
             Log.d(TAG, "Bundle received of size " + bundle.size);
           } 
        }
      }
    }
  </code></pre>
  
  <p>And this is a small extract from my Manifest</p>
  
  <pre><code>  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
    &lt;receiver 
      android:name=".LocationProviderChangedReceiver"
      android:exported="false"&gt;
      &lt;intent-filter&gt;
        &lt;action android:name="android.location.PROVIDERS_CHANGED" /&gt;
        &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
    &lt;/receiver&gt;
  </code></pre>
  
  <p>This would be perfect if there was an extra within the Broadcast that stated which provider had changed and whether it was enabled or disabled. Unfortunately this is not the case. Is anyone aware of any mechanism by which I can determine what state has changed without maintaining my own state variables.</p>
  
  <p>In an ideal world I would monitor for changes constantly but only listen for location changes occasionally. I would like to avoid constantly monitoring for location changes.</p>