How to get current battery capacity in mA of android device.

I have tried this code, but it gives me value total battery capacity:

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();
    } }

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/3b272c4f-464e-409e-9ae1-7c5d0433a417%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to