BatteryHelper
Centralized battery helper for Android.
This utility provides synchronous access and reactive flows for monitoring battery status, level, and power-saving modes.
No permissions required.
Example usage:
val batteryHelper = BatteryHelper(context)
// Synchronous check
val status = batteryHelper.getStatus()
println("${status.level}% - ${if (status.isCharging) "Charging" else "On Battery"}")
// Reactive flow
viewModelScope.launch {
batteryHelper.statusFlow.collect { status ->
updateBatteryUI(status)
}
}
// Power save mode
if (batteryHelper.isPowerSaveMode()) {
disableExpensiveAnimations()
}Content copied to clipboard
Properties
Link copied to clipboard
A Flow that emits a BatteryStatus whenever the battery state changes. It emits the current status immediately upon subscription.