title: Android: detect when GPS is turned on/off (or when no app is using it anymore)
body: <p>I'm on Android 2.3.7 and I'm trying to write a BroadcastReceiver that will get called when the user turns GPS on/off (ie: by tapping on the "use GPS satellites" in the options.</p>
  
  <p>What I've done so far is this:</p>
  
  <p>1) Created the following broadcastReceiver:</p>
  
  <pre><code>public class GPSStatusBroadcastReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context arg0, Intent arg1) {
          Toast.makeText(arg0, "Broadcast received!", Toast.LENGTH_SHORT).show();
  
      }
  }
  </code></pre>
  
  <p>2)Added this to the android manifest, inside the  tags:</p>
  
  <pre><code>&lt;receiver android:name=".GPSStatusBroadcastReceiver"&gt; 
      &lt;intent-filter&gt; 
          &lt;action android:name="android.location.PROVIDERS_CHANGED" /&gt; 
      &lt;/intent-filter&gt; 
  &lt;/receiver&gt;
  </code></pre>
  
  <p>Now the problem with this is that it appears not to be reliable. When I turn GPS on/ff the onReceive() method only runs sometimes (I'd say 1 time out 3) the other times it doesn't get called.</p>
  
  <p>I want to know if there is a reliable way to detect when the GPS is turned off/on.</p>
  
  <p>If there isn't it would be nice to be notified at least when no app is using the GPS anymoer (ie: when the gps icon disappears from statusbar, indicating no one is actively locating).</p>
  
  <p>EDIT: Clarification: I don't want to do this while my app is running. I just whatn my app to be started when gps is turned on/off, do its thing and then terminate, I don't want to subscribe to LocationsUpdates...</p>