To use Battery Plus, we provided you with easy to access API. Start by making an instance of
The available states are:
- Full: the battery is at 100%, full of energy.
- Charging: the battery is being charged.
- Discharging: the battery is losing energy.
- Unknown: unable to read the battery state or the device has no battery.
To get these information in realtime, you can subscribe to the stream from the
Trying to run this code on Android emulator will result in
Unknown state, but Android emulator provides a way of emulating the different states from its settings. By clicking the menu icon (three vertical dots) then going to battery section.
On the other hand, there is no way of doing the same on iOS simulator, you won't be able to read the state or battery percentage, so it's always
Unknown, better to debug on a real device, web or desktop.
Using the same
Battery instance, it's possible to read the current percentage of energy in the device battery.