IntentFilter batfilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent battery = registerReceiver(null, batfilter);
int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
Toast.makeText(MainActivity.this, ""+status, Toast.LENGTH_SHORT).show();