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
2010-07-16 17:20:22
Thanks! There is no way to poll for this information?
NPike
2010-07-21 02:41:31
@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
2010-07-21 12:24:59