我尝试了Android的powerprofile....我尝试了这段代码...但每次在所有设备上都给我1000个答案... 有没有其他的方法可以在Android上获取电池容量... 例如,如果移动设备容量为2000mAh,则应返回2000
public Double getBatteryCapacity() {
Object mPowerProfile_ = null;
double batteryCapacity = 0;
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) {
// Class not found?
e.printStackTrace();
}
try {
// Invoke PowerProfile method "getAveragePower" with param
// "battery.capacity"
batteryCapacity = (Double) Class.forName(POWER_PROFILE_CLASS)
.getMethod("getAveragePower", java.lang.String.class)
.invoke(mPowerProfile_, "battery.capacity");
} catch (Exception e) {
// Something went wrong
e.printStackTrace();
}
return batteryCapacity;
}