title: Why is my Receiver for charging status always returning false?
body: <p>I'm trying to detect when a user plugs (or unplugs) in their device to charge. In my receiver, where I determine whether it is plugged in or not, I always get a "false" reading on the status. Here is my code:</p>
  
  <p>(In the manifest):</p>
  
  <pre><code>&lt;receiver android:name=".PowerConnectionReceiver" &gt;
       &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED" /&gt;
            &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /&gt;
       &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>Here is the PowerConnectionReceiver class:</p>
  
  <pre><code>public class PowerConnectionReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
          boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                               status == BatteryManager.BATTERY_STATUS_FULL;
  
          Log.d("Battery", "Plugged In: " + String.valueOf(isCharging));
          Log.d("Battery", "status: " + String.valueOf(status));
      }
  }
  </code></pre>
  
  <p>What's working: The PowerConnectionReceiver properly gets called when the phone is plugged in.</p>
  
  <p>However, when I print out the status, it always returns as -1 (which is the default value I entered in). It seems the BatteryManager.EXTRA_STATUS isn't coming in properly.</p>
  
  <p>For reference, here is what those Logs are printing out:</p>
  
  <pre><code>"Plugged In: false"
  "status: -1"
  </code></pre>
  
  <p>More reference - here is the page on the Developers site I am using for this:
  <a href="http://developer.android.com/training/monitoring-device-state/battery-monitoring.html" rel="nofollow">http://developer.android.com/training/monitoring-device-state/battery-monitoring.html</a></p>