1. Download our Official Android App: Forums for Android!

Apps Get current milliAmps of battery

Discussion in 'Android Development' started by hndao, Jul 4, 2016.

  1. hndao

    hndao Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jun 29, 2016

    Jun 29, 2016
    2
    0
    5
    Male
    Liverpool city
    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();
    }
    }
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,872
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,872
    11,505
    1,988
    Male
    Software developer
    South West of England
  3. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    It think your code is designed to get battery information. What I would do is get your battery information and then get the total charge of the battery and kind of gusetimate the mA from the % charged and the total battery mA
     

Share This Page

Loading...