Getting battery information in Android

Download source code of the article.

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.

1 Comment

Add yours →

  1. hello, I tried to download the project in the link but could not.
    this could release for download again in repository?
    I really need study this project!!
    thanks.
    really not have project in portuguese in such detail!

Leave a Reply