
To get the percentage of battery charge in an android device, we can use the following code:
BatteryManager bm=(BatteryManager)getSystemService(BATTERY_SERVICE);
int battery_percent = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
If we have a TextView textview1 on the activity, to display the battery percentage in textview1 we can use following code else please change the textview1 to the id of the text view which you want to display the battery PERCENTAGE.
textview1.setText(battery_percent + "%");
Thanks for viewing the page 😀😀.
If the code doesn’t work please contact on educlick.gsoft@gmail.com