To check your device’s charge using AC / USB , try this,
Call registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)) . This will return an intent that has additional parameters defined on the BatteryManager so you know if it is connected or not.
Something with the code,
public class PowerUtil { public static boolean isConnected(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB; } }
source share