tags:

views:

45

answers:

1

Is there an easy way to be notified when USB or AC power is connected to an Android phone?

+1  A: 

Set up a BroadcastReceiver for ACTION_BATTERY_CHANGED. An Intent extra will tell you what the charging state is -- see BatteryManager for details.

CommonsWare
Thanks! There is no way to poll for this information?
NPike
@NPike: `ACTION_BATTERY_CHANGED` is a sticky broadcast. You can call `registerReceiver()` with an `IntentFilter` for `ACTION_BATTERY_CHANGED` and a `null` `BroadcastReceiver`, and you will get back the `Intent` that was last broadcast, which will tell you what the current battery charging state is.
CommonsWare