有没有办法或如何了解或了解电池的使用寿命?我正在制作电池信息,就像电池医生保护专业人员"不同之处在于我需要的寿命。我对如何做到这一点没有任何想法。谁能帮我这个?谢谢你的帮助。 :)到目前为止,这是我的代码没有" Life Span"我说的。
private BroadcastReceiver battery_receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
boolean isPresent = intent.getBooleanExtra("present", false);
String technology = intent.getStringExtra("technology");
int plugged = intent.getIntExtra("plugged", -1);
int scale = intent.getIntExtra("scale", -1);
int health = intent.getIntExtra("health", 0);
int status = intent.getIntExtra("status", 0);
int rawlevel = intent.getIntExtra("level", -1);
int level = 0;
Bundle bundle = intent.getExtras();
Log.i("BatteryLevel", bundle.toString());
if (isPresent) {
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
String info = "Battery Level: " + level + "%\n";
info += ("Technology: " + technology + "\n");
info += ("Plugged: " + getPlugTypeString(plugged) + "\n");
info += ("Health: " + getHealthString(health) + "\n");
info += ("Status: " + getStatusString(status) + "\n");
setBatteryLevelText(info + "\n\n" + bundle.toString());
} else {
setBatteryLevelText("Battery not present!!!");
}
}
};
private String getPlugTypeString(int plugged) {
String plugType = "Unknown";
switch (plugged) {
case BatteryManager.BATTERY_PLUGGED_AC:
plugType = "AC";
break;
case BatteryManager.BATTERY_PLUGGED_USB:
plugType = "USB";
break;
}
return plugType;
}
private String getHealthString(int health) {
String healthString = "Unknown";
switch (health) {
case BatteryManager.BATTERY_HEALTH_DEAD:
healthString = "Dead";
break;
case BatteryManager.BATTERY_HEALTH_GOOD:
healthString = "Good Condition";
break;
case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
healthString = "Over Voltage";
break;
case BatteryManager.BATTERY_HEALTH_OVERHEAT:
healthString = "Over Heat";
break;
case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
healthString = "Failure";
break;
}
return healthString;
}
private String getStatusString(int status) {
String statusString = "Unknown";
switch (status) {
case BatteryManager.BATTERY_STATUS_CHARGING:
statusString = "Charging";
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
statusString = "Discharging";
break;
case BatteryManager.BATTERY_STATUS_FULL:
statusString = "Full";
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
statusString = "Not Charging";
break;
}
return statusString;
}
答案 0 :(得分:0)
正如我在Get the remaining battery time available from an Android phone上所说的那样,你需要获得当前的电池电量并计算出当前电量消耗的速度。这将取决于处理器负载,屏幕亮度,哪些无线电有效,以及可能还有其他因素。
简短的回答,肯定有可能得到一个估计,但这并不容易,可能不是很准确
答案 1 :(得分:0)
不完全确定您在此处尝试做什么,计算瓦特小时数或安培小时数检查此链接: http://www.powerstream.com/battery-capacity-calculations.htm 如果你想在你当前使用的电池上剩下的时间,你需要获得当前的电池电量,然后知道它的排水速度,通过检查它在那之前排出的速度然后做出假设或者通过知道你将绘制多少电流。
如果您使用正确的电池校准代码
,将获得最佳效果(看起来我被打败了答案;))