Code for Battery Percentage

 Set these codes in the first "add source directly":

BatteryManager bm=(BatteryManager)getSystemService(BATTERY_SERVICE);


int battery_percent = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);


textview1.setText(battery_percent + "%");


Set these codes on the 2nd "add source directly":

IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

Intent batteryStatus = registerReceiver(null, ifilter);

int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);

if(status == BatteryManager.BATTERY_STATUS_FULL) {

Toast.makeText(getApplicationContext(),"Device is fully charged",Toast.LENGTH_LONG).show(); } else {

Toast.makeText(getApplicationContext(),"Device is not fully charged",Toast.LENGTH_LONG).show(); }

Comments

Popular posts from this blog

Voice recorder

Code for "Loading Dialog Box"

Code for "Image share from app"