Wednesday, 21 January 2015

How to get battery level.

How to get current battery charged level.

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(

int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

return level / (float) scale * 100.0f;