Can’t tell how much an app is battery/power consuming(1).
However it is possible to know what is the current battery level:
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPct = level / (float)scale;
whether the battery is being charged or not:
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING;
boolean isCharged = status == BatteryManager.BATTERY_STATUS_FULL;
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
See in the documentation how Monitor load status changes and Monitor significant battery level changes.
References
(1) It is not possible to know programmatically but it is possible to use the adb to dump the collected battery usage data to the pc and create a report that can be analyzed using the Battery Historian.
So, I came to give a read on, but it wasn’t exactly what I needed, but thank you :)
– Wallace Baldenebre