如何在Android电池使用状况确定的? [英] How is the Android battery health determined?
本文介绍了如何在Android电池使用状况确定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不是在谈论如何读出的值。
I am not talking about how to read the value.
相反,我感兴趣的是如何BatteryManager.EXTRA_HEALTH的值被设置。
Rather, I am interested in how the value of BatteryManager.EXTRA_HEALTH is being set.
它来自固件?制造商特定的?
Does it come from the firmware? Manufacturer specific?
什么决定了这些价值?
int BATTERY_HEALTH_COLD
int BATTERY_HEALTH_DEAD
int BATTERY_HEALTH_GOOD
int BATTERY_HEALTH_OVERHEAT
int BATTERY_HEALTH_OVER_VOLTAGE
int BATTERY_HEALTH_UNKNOWN
int BATTERY_HEALTH_UNSPECIFIED_FAILURE
谢谢, 西蒙
Thanks, Simon
推荐答案
通过使用这种code就可以得到有关的电池信息。
By using this code you can get information regarding battery..
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;
String temp=null;
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");
info += ("Temp: "+getTempStatus(temp,intent)+"\n");
setBatteryLevelText(info + "\n\n" + bundle.toString());
}
else
{
setBatteryLevelText("Battery not present!!!");
}
}
};
private void registerBatteryLevelReceiver(){
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(battery_receiver, filter);
}
这篇关于如何在Android电池使用状况确定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文