0

Question kinda sais it:

How can I detect if the USB cable (and maybe thus power?) was disconnected from the device? I thought there would be some manifest permission that I could use to google around but I didn't find anything).

Also there was somebody here on Stackoverflow that said something about not detecting the usb removal but the change of charging status but I lost the link and couldn't for the love of god find it again :< Hope you have some ideas what I could do.

AreusAstarte
  • 1,958
  • 2
  • 17
  • 29
  • 1
    See Here: http://stackoverflow.com/questions/5283491/android-check-if-device-is-plugged-in – FoamyGuy Feb 19 '13 at 22:28
  • ah...I didn't think about searching for "is it plugged in" :') thanks – AreusAstarte Feb 19 '13 at 22:32
  • Wouldn't some of the other states work better for the actual question(referring to your edit with code)? Won't `STATUS_CHARGING` fail if it's fully charged? `STATUS_FULL` would be a good one to check for also. Or, more specific to the question, `EXTRA_PLUGGED` in conjunction with `BATTERY_PLUGGED_USB`. – Geobits Feb 19 '13 at 23:36
  • Hmm, well I guess there could be better states. First off the BATTERY_STATUS_CHARGING will still apply if the battery is fully charged, as it will still have the "charging" flag until the cable is unplugged. But I seriously didn't go through all the flags. I'll try the ones you listed. Thanks for the addition – AreusAstarte Feb 20 '13 at 00:25

1 Answers1

0

You can receive power connected or disconnected events, like this:

<receiver android:name=".PowerConnectionReceiver">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
    <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
  </intent-filter>
</receiver>
ajpolt
  • 1,002
  • 6
  • 10