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

TextInputLayout in Sketchware

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

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation