Battery Health
//onCreate
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
getApplicationContext().registerReceiver(mBroadcastReceiver,iFilter);
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "Received", Toast.LENGTH_SHORT).show();
int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH,0);
String healthString = "";
// Determine the battery health from return integer value
if(health == BatteryManager.BATTERY_HEALTH_COLD){
healthString = "COLD";
}else if (health == BatteryManager.BATTERY_HEALTH_DEAD){
healthString = "DEAD";
}else if (health == BatteryManager.BATTERY_HEALTH_GOOD){
healthString = "GOOD";
}else if (health == BatteryManager.BATTERY_HEALTH_OVERHEAT){
healthString = "OVER HEAT";
}else if (health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
healthString = "OVER VOLTAGE";
}else if(health == BatteryManager.BATTERY_HEALTH_UNKNOWN){
healthString = "UNKNOWN";
}else if(health == BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE){
healthString = "UNSPECIFIED FAILURE";
}
textview1.setText("Battery Health : " + healthString);
}
};
Comments