Added in API level 31

BatteryState

abstract class BatteryState
kotlin.Any
   ↳ android.hardware.BatteryState

The BatteryState class is a representation of a single battery on a device.

Summary

Constants
static Int

Battery is charging.

static Int

Battery is discharging.

static Int

Battery is full.

static Int

Battery is connected to power but not charging.

static Int

Battery status is unknown.

Public constructors

Public methods
abstract Float

Get remaining battery capacity as float percentage [0.

abstract Int

Get the battery status.

abstract Boolean

Check whether the hardware has a battery.

Constants

STATUS_CHARGING

Added in API level 31
static val STATUS_CHARGING: Int

Battery is charging.

Value: 2

STATUS_DISCHARGING

Added in API level 31
static val STATUS_DISCHARGING: Int

Battery is discharging.

Value: 3

STATUS_FULL

Added in API level 31
static val STATUS_FULL: Int

Battery is full.

Value: 5

STATUS_NOT_CHARGING

Added in API level 31
static val STATUS_NOT_CHARGING: Int

Battery is connected to power but not charging.

Value: 4

STATUS_UNKNOWN

Added in API level 31
static val STATUS_UNKNOWN: Int

Battery status is unknown.

Value: 1

Public constructors

BatteryState

BatteryState()

Public methods

getCapacity

Added in API level 31
abstract fun getCapacity(): Float

Get remaining battery capacity as float percentage [0.0f, 1.0f] of total capacity Returns NaN when battery capacity can't be read.

Return
Float the battery capacity. Value is between -1.0f and 1.0f inclusive

isPresent

Added in API level 31
abstract fun isPresent(): Boolean

Check whether the hardware has a battery.

Return
Boolean True if the hardware has a battery, else false.