Android – Getting Battery Information

We have many apps on play store which gives battery information along with many other CPU informations such as CPU-Z, CPU X etc. In Android, one can easily obtain the battery information at any point in time using the BatteryManager class . It  contains several strings and constants used for values in the ACTION_BATTERY_CHANGED Intent. Android Developers can display these values using an appropriate Views in their application.

Using the Battery API one can get a battery’s level, voltage, temperature, technology, charging status, health and even an icon representing the current state of the battery. Through this post, we will learn how to display the battery information in Android App.

Step 1 ) Create xml in layout 


Step 2 ) Create Activity and Register Broadcast Receiver .

To fetch battery information in android you need to create new activity class named BatteryInfoActivity in your existing android project. In order to receive the updated information from the battery we need to register a BroadcastReceiver and an IntentFilter.


Enjoy Coding and Share Knowledge