I know there are many questions like this, but I need a concrete answer whether it is possible or not.
I want to get the current available battery power in mAh for any android phone. It is crucial for my project. I tried BatteryManager.
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER);
It exactly provides the information I need, but only for some devices.
I also tried using PowerProfile via Java Reflection.
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(OffloadeeActivity.this, batteryCapacity + " mAh",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
But it provides the total battery capacity. What I need is the current remaining battery power. Is there any universal way to get that for every device? Any library would also do.