Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TextView batteryView = (TextView) findViewById(R.id.batteryView);
- IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
- Intent batteryStatus = getApplicationContext().registerReceiver(null, ifilter);
- int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
- int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
- float batteryPct = level / (float)scale;
- int batteryPercentage = (int)(batteryPct*100);
- batteryView.setText("Bateria: " + batteryPercentage + "%");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement