Showing posts from December, 2016

Show the updated battery status in Android

Have a happy holidays. After a long time, I'm blog here such a good topic.

Here I explain about the battery status on real time. Yes, you can use BatteryManager to get the battery status. But you want to know the updated status on all time means, you need to use BroadcastReceiver.

You can add on your activity.

 private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {

            int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
            int icon_small = intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0);
            int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            boolean present = intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
            int status = intent.getIntExtra(BatteryMa…