BatteryState


public abstract class BatteryState
extends Object

java.lang.Object
   ↳ android.hardware.BatteryState


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

Summary

Constants

int STATUS_CHARGING

Battery is charging.

int STATUS_DISCHARGING

Battery is discharging.

int STATUS_FULL

Battery is full.

int STATUS_NOT_CHARGING

Battery is connected to power but not charging.

int STATUS_UNKNOWN

Battery status is unknown.

Public constructors

BatteryState()

Public methods

abstract float getCapacity()

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

abstract int getStatus()

Get the battery status.

abstract boolean isPresent()

Check whether the hardware has a battery.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Constants

STATUS_CHARGING

Added in API level 31
public static final int STATUS_CHARGING

Battery is charging.

Constant Value: 2 (0x00000002)

STATUS_DISCHARGING

Added in API level 31
public static final int STATUS_DISCHARGING

Battery is discharging.

Constant Value: 3 (0x00000003)

STATUS_FULL

Added in API level 31
public static final int STATUS_FULL

Battery is full.

Constant Value: 5 (0x00000005)

STATUS_NOT_CHARGING

Added in API level 31
public static final int STATUS_NOT_CHARGING

Battery is connected to power but not charging.

Constant Value: 4 (0x00000004)

STATUS_UNKNOWN

Added in API level 31
public static final int STATUS_UNKNOWN

Battery status is unknown.

Constant Value: 1 (0x00000001)

Public constructors

BatteryState

public BatteryState ()

Public methods

getCapacity

Added in API level 31
public abstract float getCapacity ()

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

Returns
float the battery capacity. Value is between -1.0f and 1.0f inclusive

getStatus

Added in API level 31
public abstract int getStatus ()

Get the battery status.

Returns
int the battery status. Value is STATUS_UNKNOWN, STATUS_CHARGING, STATUS_DISCHARGING, STATUS_NOT_CHARGING, or STATUS_FULL

isPresent

Added in API level 31
public abstract boolean isPresent ()

Check whether the hardware has a battery.

Returns
boolean True if the hardware has a battery, else false.