Getting battery information in Android

by Krishnaraj Varma on July 11, 2010

in Android

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.

Previous post:

Next post:

Disclaimer: This is a personal weblog. The information in this weblog is provided “AS IS” with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.