I want to get battery capacity of a device to do some battery consumption computation, is it possible to get it somehow? For instance, battery capacity for Samsung Galaxy Note 2 is 3100 mah. Thanks for helping.
Milliamp-hours, or mAh, are the units technicians use to measure a battery's useful operating lifetime, or how long the battery will last when it powers a normal electrical load. You can measure a battery's mAh rating using a multimeter, a resistor to act as a load and a stopwatch to measure elapsed time.
Find battery capacity (mAh) from Android settings First, open Settings app in your phone. Scroll down to the bottom and click About option. Under Battery Information, you will see the battery capacity of your Android phone. Here you will also see the battery level and status (charging or not charging).
Open your phone's Settings app. Under "Battery," see how much charge you have left, and about how long it will last. For details, tap Battery. For a graph and list of battery use, tap Battery Usage.
Got it! Couldn't find anything straight in SDK but can be done using reflection.
Here is the working code :-
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With