2014-04-21 2 views
6

Android 배터리 총 용량 (mAh) 및 현재 배터리 용량 (mA).Android 배터리의 현재 용량 (mA) 및 총 배터리 용량 (mAh)

+0

객체 mPowerProfile_ = Class.forName을 (POWER_PROFILE_CLASS) .getConstructor (Context.class) .newInstance (이); 배터리 용량 = (Double) Class.forName (POWER_PROFILE_CLASS) .getMethod ("getAveragePower" –

+0

http://andackoverflow.com/questions/22243461/android-is-there-anyway-to-get-battery-capacity-of-a-device-in-mah –

+0

총 배터리 용량을 mAh로 얻을 수 있습니다. 하지만 배터리 방전 시간을 얻고 싶습니다. 그래서 mA에서 배터리 전류 용량을 어떻게 얻을 수 있는지 알고 싶습니다. –

답변

17

이 시도 ..

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

Android 버전 Lollipop에서 Oreo로 테스트되었습니다. 아직 손상되지 않았습니다. 올바른 배터리 용량 값을 얻는 중입니다. –