title: Obtaining usb cable plugged IN/OUT event using EXTRA_PLUGGED does not work
body: <p>My intention is to have saved in Preferences current status of Android device usb/power cable: connected/disconnected. From Developer site I see that there are two Intent for obtaining that status: ACTION_POWER_CONNECTED / DISCONNECTED. So I used same code as published at Developers:</p>
  
  <p><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>
  
  <p>in section Monitor Changes in Charging State.</p>
  
  <p><strong>Manifest</strong></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><strong>Java code</strong></p>
  
  <pre><code>public class PowerConnectionReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) { 
  
          int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
          boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
          boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
  
          Toast.makeText(context, "pvr = " + usbCharge + ", " + acCharge + "," + isCharging, Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>When I am plugging USB cable IN/OUT than broadcast is always correctly sent and caught in PowerConnectionReceiver but always with same result (=cable is plugged out). </p>
  
  <p>I tested it with Galaxy Nexus 4.1.1 / 4.2.1 - I am always getting 2xFALSE in Toast (chargePlug = FALSE, usbCharge = FALSE).</p>
  
  <p><strong>Why</strong> intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <strong>always return default value "-1" ?</strong></p>
  
  <p>Thank you.</p>
  
  <p>ps. everything works fine if I register receiver in Java</p>
  
  <pre><code>Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  </code></pre>
  
  <p>...in Service or in Activity. But according to Android Developers site it is not prerequisity to make code above to return correct value;</p>