Android Get Battery total capacity in mAh and Current Battery Capacity in mA.
Asked
Active
Viewed 9,516 times
7
-
object mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS).getConstructor(Context.class).newInstance(this); batteryCapacity = (Double) Class.forName(POWER_PROFILE_CLASS) .getMethod("getAveragePower", java.lang.String.class).invoke(mPowerProfile_, "battery.capacity"); – Uma Shankar Apr 21 '14 at 08:05
-
http://stackoverflow.com/questions/22243461/android-is-there-anyway-to-get-battery-capacity-of-a-device-in-mah – Sebastien Bianchi Apr 21 '14 at 08:06
-
I am able to get total capacity of battery in mAh but i want to get battery discharge time so now i want to know how i can get battery current capacity in mA. – Uma Shankar Apr 21 '14 at 08:11
-
how did you calculate battery discharge time? – Kaushal28 Nov 22 '17 at 17:13
1 Answers
21
Try this..
public void getBatteryCapacity() {
Object mPowerProfile_ = null;
final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";
try {
mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS)
.getConstructor(Context.class).newInstance(this);
} catch (Exception e) {
e.printStackTrace();
}
try {
double batteryCapacity = (Double) Class
.forName(POWER_PROFILE_CLASS)
.getMethod("getAveragePower", java.lang.String.class)
.invoke(mPowerProfile_, "battery.capacity");
Toast.makeText(MainActivity.this, batteryCapacity + " mah",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}

Akshay
- 6,029
- 7
- 40
- 59
-
1Tested this method on Android versions Lollipop to Oreo - it's not broken yet. Getting correct battery capacity values. – Darpan Nov 27 '17 at 08:11
-
This is not working for me in Android L, I'm checking in Vivo y21 device which contains 1900mAh battery, but I'm getting 3900mAh – Suresh Jul 06 '20 at 11:37
-
Those values are hard-coded by manufacturer. Hence some device just report crap information. There is another method (standard API) but it never returns the same value: https://stackoverflow.com/questions/27998034/total-battery-capacity-in-mah-of-device-programmatically – 3c71 Aug 16 '20 at 20:20