Download Battery Info Sample (58)
To get the battery information in Android we register a broadcast receiver with intent filter Intent.ACTION_BATTERY_CHANGED. In onReceive method, the intent received will have battery information. The intent contains many useful information about the battery, some of the bundle keys are :
-
present
technology
plugged
scale
health
voltage
level
temperature
status
In API versions higher than 5, the BatteryManager has the constants for these keys. In lesser versions we have to hard-code these keys (I used Bundle.toString() method to get all the keys).
The battery level information is calculated by using the formula (level * 100) / scale.
You must log in to post a comment.