How to get current battery charged level.
Use this method to get the current battery level in android.
Determine the Current Battery Level
Use this method to get the current battery level in android.
public float getCurrentBatteryLevel(Context context) {
Intent batteryStatus = context.registerReceiver(null, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
return level / (float) scale * 100.0f;
}
Intent batteryStatus = context.registerReceiver(null, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
return level / (float) scale * 100.0f;
}