我已经尝试过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;
}