Is there an easy way to be notified when USB or AC power is connected to an Android phone?
In AndroidManifest.xml
In Code
public class PlugInControlReceiver extends BroadcastReceiver {
public void onReceive(Context context , Intent intent) {
String action = intent.getAction();
if(action.equals(Intent.ACTION_POWER_CONNECTED)) {
// Do something when power connected
}
else if(action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
// Do something when power disconnected
}
}
}