I was wondering if it was possible to specifically determine if an Android device was plugged into a computer or just power.
The main reason is I’d like for my phone to “Stay Awake” when it’s plugged into a computer while I’m developing, but not when it’s plugged into a power outlet a night.
I was thinking that if I could tell what I’m connected to, I could use ACTION_POWER_CONNECTED to start up a service and check what USB I’m connected to.
I actually found the exact way to choose whether to keep the screen on when plugged into AC, USB or either by looking into the source at http://google.com/codesearch#409TP6F96yI/src/com/android/settings/DevelopmentSettings.java&l=95
Requires permission:
android.permission.WRITE_SETTINGSFor AC:
BatteryManager.BATTERY_PLUGGED_ACFor USB:
BatteryManager.BATTERY_PLUGGED_USBFor Either:
(BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB)