I've been searching for this and only find really messed up things. Isn't there a easy way to show the battery level like 21% on a toast or Textview? Or how can i achieve this?
//Simon
To get the battery level right now, call:
registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
(note: typing that in from memory, please adjust if needed)
This will return an Intent
with various extras documented on the BatteryManager
class. Use BatteryManager.EXTRA_LEVEL
and BatteryManager.EXTRA_SCALE
to determine the percentage remaining.
If you need to know over a period of time as the battery changes, use the BroadcastReceiver
approach @Augusto outlined in his answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With