BatteryHelper

class BatteryHelper(context: Context)(source)

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()
}

Constructors

Link copied to clipboard
constructor(context: Context)

Properties

Link copied to clipboard

A Flow that emits a BatteryStatus whenever the battery state changes. It emits the current status immediately upon subscription.

Functions

Link copied to clipboard
fun getLevel(): Int?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard