BroadCast Battery Healt

//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);
}
};

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

A Flash Light App in Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Firebase Login/Register with email verification

Codes for modifying Action Bar in Sketchware

Code for implementing Notifications in Sketchware