4

I wanted to know that how can we find how much time android device will take to fully charge its battery.

For example if my battery is 0% charged then how long it will take to charge full i.e. 100%, same if my device is 70% charge so if i connect charger now then how long it will take to full charge my device.

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
user1346836
  • 147
  • 1
  • 3
  • 12

2 Answers2

2

This worked for me:

private void batteryLevel() {
        BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                context.unregisterReceiver(this);
                int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                int level = -1;
                if (rawlevel >= 0 && scale > 0) {
                    level = (rawlevel * 100) / scale;
                }
                batterLevel.setText("Battery Level Remaining: " + level + "%");
            }
        };
        IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        registerReceiver(batteryLevelReceiver, batteryLevelFilter);
    }

See also: http://mihaifonoage.blogspot.de/2010/02/getting-battery-level-in-android-using.html

Thkru
  • 4,218
  • 2
  • 18
  • 37
  • 2
    Good read, but he needs the time required to complete the charge. Anyways, Voted up. – 0xC0DED00D Jun 20 '12 at 07:22
  • As @noob said, this answer only gives a partial solution. Shows you how to get the values but not what you do with them to get the time remaining. – Bamerza Feb 06 '15 at 07:34
1

You should read the official documentation about this. Basically you'll need to use BatteryManager class to find out current state of battery level.

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
  • Creator Thanks for your reply, i am able to find the battery level but i not finding the recharge time how much more time my battery requires for full charge. please help me on this thanks for your prev. reply – user1346836 Jun 19 '12 at 10:20
  • 4
    BatteryManager doesn't provide this information, but you can do it using simple logic, check what's the time last 1 percentage change took, and multiply that time to remaining percentage of charge. Since this time keeps on changing, you need to update the time/percentage frequently using a thread. – 0xC0DED00D Jun 19 '12 at 10:32
  • @noob how can i convert time elapse (msecs) in hours and in minutes – Erum Jan 06 '15 at 12:06
  • @ErumHannan you should ask a new question for this. – 0xC0DED00D Jan 06 '15 at 12:08