java
private int getSystemBattery(Context context) {
int level = 0;
Intent batteryInfoIntent = context.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
level = batteryInfoIntent.getIntExtra("level", 0);
int batterySum = batteryInfoIntent.getIntExtra("scale", 100);
int percentBattery= 100 * level / batterySum;
return percentBattery;
}