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.
You should read the official documentation about this. Basically you'll need to use BatteryManager
class to find out current state of battery level.
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
来源:https://stackoverflow.com/questions/11098779/how-to-find-the-battery-recharge-time-of-android-mobile-programatically