public abstract class BatteryState
extends Object



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

From class java.lang.Object

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

public static final int STATUS_CHARGING

Battery is charging.

Constant Value: 2 (0x00000002)

STATUS_DISCHARGING

public static final int STATUS_DISCHARGING

Battery is discharging.

Constant Value: 3 (0x00000003)

STATUS_FULL

public static final int STATUS_FULL

Battery is full.

Constant Value: 5 (0x00000005)

STATUS_NOT_CHARGING

public static final int STATUS_NOT_CHARGING

Battery is connected to power but not charging.

Constant Value: 4 (0x00000004)

STATUS_UNKNOWN

public static final int STATUS_UNKNOWN

Battery status is unknown.

Constant Value: 1 (0x00000001)

Public constructors

BatteryState

public BatteryState ()

Public methods

getCapacity

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

isPresent

public abstract boolean isPresent ()

Check whether the hardware has a battery.

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

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-13 UTC.