BatteryManager
public
class
BatteryManager
extends Object
| java.lang.Object | |
| ↳ | android.os.BatteryManager |
The BatteryManager class contains strings and constants used for values
in the ACTION_BATTERY_CHANGED Intent, and
provides a method for querying battery and charging properties.
Summary
Constants | |
|---|---|
String |
ACTION_CHARGING
Sent when the device's battery has started charging (or has reached full charge and the device is on power). |
String |
ACTION_DISCHARGING
Sent when the device's battery may be discharging, so apps should avoid doing extraneous work that would cause it to discharge faster. |
int |
BATTERY_HEALTH_COLD
|
int |
BATTERY_HEALTH_DEAD
|
int |
BATTERY_HEALTH_GOOD
|
int |
BATTERY_HEALTH_OVERHEAT
|
int |
BATTERY_HEALTH_OVER_VOLTAGE
|
int |
BATTERY_HEALTH_UNKNOWN
|
int |
BATTERY_HEALTH_UNSPECIFIED_FAILURE
|
int |
BATTERY_PLUGGED_AC
Power source is an AC charger. |
int |
BATTERY_PLUGGED_USB
Power source is a USB port. |
int |
BATTERY_PLUGGED_WIRELESS
Power source is wireless. |
int |
BATTERY_PROPERTY_CAPACITY
Remaining battery capacity as an integer percentage of total capacity (with no fractional part). |
int |
BATTERY_PROPERTY_CHARGE_COUNTER
Battery capacity in microampere-hours, as an integer. |
int |
BATTERY_PROPERTY_CURRENT_AVERAGE
Average battery current in microamperes, as an integer. |
int |
BATTERY_PROPERTY_CURRENT_NOW
Instantaneous battery current in microamperes, as an integer. |
int |
BATTERY_PROPERTY_ENERGY_COUNTER
Battery remaining energy in nanowatt-hours, as a long integer. |
int |
BATTERY_PROPERTY_STATUS
Battery charge status, from a BATTERY_STATUS_* value. |
int |
BATTERY_STATUS_CHARGING
|
int |
BATTERY_STATUS_DISCHARGING
|
int |
BATTERY_STATUS_FULL
|
int |
BATTERY_STATUS_NOT_CHARGING
|
int |
BATTERY_STATUS_UNKNOWN
|
String |
EXTRA_HEALTH
Extra for |
String |
EXTRA_ICON_SMALL
Extra for |
String |
EXTRA_LEVEL
Extra for |
String |
EXTRA_PLUGGED
Extra for |
String |
EXTRA_PRESENT
Extra for |
String |
EXTRA_SCALE
Extra for |
String |
EXTRA_STATUS
Extra for |
String |
EXTRA_TECHNOLOGY
Extra for |
String |
EXTRA_TEMPERATURE
Extra for |
String |
EXTRA_VOLTAGE
Extra for |
Public methods | |
|---|---|
int
|
getIntProperty(int id)
Return the value of a battery property of integer type. |
long
|
getLongProperty(int id)
Return the value of a battery property of long type If the platform does not provide the property queried, this value will be Long.MIN_VALUE. |
boolean
|
isCharging()
Return true if the battery is currently considered to be charging. |
Inherited methods | |
|---|---|
java.lang.Object
| |
Constants
ACTION_CHARGING
String ACTION_CHARGING
Sent when the device's battery has started charging (or has reached full charge
and the device is on power). This is a good time to do work that you would like to
avoid doing while on battery (that is to avoid draining the user's battery due to
things they don't care enough about).
This is paired with ACTION_DISCHARGING. The current state can always
be retrieved with isCharging().
Constant Value: "android.os.action.CHARGING"
ACTION_DISCHARGING
String ACTION_DISCHARGING
Sent when the device's battery may be discharging, so apps should avoid doing
extraneous work that would cause it to discharge faster.
This is paired with ACTION_CHARGING. The current state can always
be retrieved with isCharging().
Constant Value: "android.os.action.DISCHARGING"
BATTERY_HEALTH_OVERHEAT
int BATTERY_HEALTH_OVERHEAT
Constant Value: 3 (0x00000003)
BATTERY_HEALTH_OVER_VOLTAGE
int BATTERY_HEALTH_OVER_VOLTAGE
Constant Value: 5 (0x00000005)
BATTERY_HEALTH_UNKNOWN
int BATTERY_HEALTH_UNKNOWN
Constant Value: 1 (0x00000001)
BATTERY_HEALTH_UNSPECIFIED_FAILURE
int BATTERY_HEALTH_UNSPECIFIED_FAILURE
Constant Value: 6 (0x00000006)
BATTERY_PLUGGED_AC
int BATTERY_PLUGGED_AC
Power source is an AC charger.
Constant Value: 1 (0x00000001)
BATTERY_PLUGGED_USB
int BATTERY_PLUGGED_USB
Power source is a USB port.
Constant Value: 2 (0x00000002)
BATTERY_PLUGGED_WIRELESS
int BATTERY_PLUGGED_WIRELESS
Power source is wireless.
Constant Value: 4 (0x00000004)
BATTERY_PROPERTY_CAPACITY
int BATTERY_PROPERTY_CAPACITY
Remaining battery capacity as an integer percentage of total capacity (with no fractional part).
Constant Value: 4 (0x00000004)
BATTERY_PROPERTY_CHARGE_COUNTER
int BATTERY_PROPERTY_CHARGE_COUNTER
Battery capacity in microampere-hours, as an integer.
Constant Value: 1 (0x00000001)
BATTERY_PROPERTY_CURRENT_AVERAGE
int BATTERY_PROPERTY_CURRENT_AVERAGE
Average battery current in microamperes, as an integer. Positive values indicate net current entering the battery from a charge source, negative values indicate net current discharging from the battery. The time period over which the average is computed may depend on the fuel gauge hardware and its configuration.
Constant Value: 3 (0x00000003)
BATTERY_PROPERTY_CURRENT_NOW
int BATTERY_PROPERTY_CURRENT_NOW
Instantaneous battery current in microamperes, as an integer. Positive values indicate net current entering the battery from a charge source, negative values indicate net current discharging from the battery.
Constant Value: 2 (0x00000002)
BATTERY_PROPERTY_ENERGY_COUNTER
int BATTERY_PROPERTY_ENERGY_COUNTER
Battery remaining energy in nanowatt-hours, as a long integer.
Constant Value: 5 (0x00000005)
BATTERY_PROPERTY_STATUS
int BATTERY_PROPERTY_STATUS
Battery charge status, from a BATTERY_STATUS_* value.
Constant Value: 6 (0x00000006)
BATTERY_STATUS_CHARGING
int BATTERY_STATUS_CHARGING
Constant Value: 2 (0x00000002)
BATTERY_STATUS_DISCHARGING
int BATTERY_STATUS_DISCHARGING
Constant Value: 3 (0x00000003)
BATTERY_STATUS_NOT_CHARGING
int BATTERY_STATUS_NOT_CHARGING
Constant Value: 4 (0x00000004)
BATTERY_STATUS_UNKNOWN
int BATTERY_STATUS_UNKNOWN
Constant Value: 1 (0x00000001)
EXTRA_HEALTH
String EXTRA_HEALTH
Extra for ACTION_BATTERY_CHANGED:
integer containing the current health constant.
Constant Value: "health"
EXTRA_ICON_SMALL
String EXTRA_ICON_SMALL
Extra for ACTION_BATTERY_CHANGED:
integer containing the resource ID of a small status bar icon
indicating the current battery state.
Constant Value: "icon-small"
EXTRA_LEVEL
String EXTRA_LEVEL
Extra for ACTION_BATTERY_CHANGED:
integer field containing the current battery level, from 0 to
EXTRA_SCALE.
Constant Value: "level"
EXTRA_PLUGGED
String EXTRA_PLUGGED
Extra for ACTION_BATTERY_CHANGED:
integer indicating whether the device is plugged in to a power
source; 0 means it is on battery, other constants are different
types of power sources.
Constant Value: "plugged"
EXTRA_PRESENT
String EXTRA_PRESENT
Extra for ACTION_BATTERY_CHANGED:
boolean indicating whether a battery is present.
Constant Value: "present"
EXTRA_SCALE
String EXTRA_SCALE
Extra for ACTION_BATTERY_CHANGED:
integer containing the maximum battery level.
Constant Value: "scale"
EXTRA_STATUS
String EXTRA_STATUS
Extra for ACTION_BATTERY_CHANGED:
integer containing the current status constant.
Constant Value: "status"
EXTRA_TECHNOLOGY
String EXTRA_TECHNOLOGY
Extra for ACTION_BATTERY_CHANGED:
String describing the technology of the current battery.
Constant Value: "technology"
EXTRA_TEMPERATURE
String EXTRA_TEMPERATURE
Extra for ACTION_BATTERY_CHANGED:
integer containing the current battery temperature.
Constant Value: "temperature"
EXTRA_VOLTAGE
String EXTRA_VOLTAGE
Extra for ACTION_BATTERY_CHANGED:
integer containing the current battery voltage level.
Constant Value: "voltage"
Public methods
getIntProperty
int getIntProperty (int id)
Return the value of a battery property of integer type. If the platform does not provide the property queried, this value will be Integer.MIN_VALUE.
| Parameters | |
|---|---|
id |
int: identifier of the requested property |
| Returns | |
|---|---|
int |
the property value, or Integer.MIN_VALUE if not supported. |
getLongProperty
long getLongProperty (int id)
Return the value of a battery property of long type If the platform does not provide the property queried, this value will be Long.MIN_VALUE.
| Parameters | |
|---|---|
id |
int: identifier of the requested property |
| Returns | |
|---|---|
long |
the property value, or Long.MIN_VALUE if not supported. |
isCharging
boolean isCharging ()
Return true if the battery is currently considered to be charging. This means that
the device is plugged in and is supplying sufficient power that the battery level is
going up (or the battery is fully charged). Changes in this state are matched by
broadcasts of ACTION_CHARGING and ACTION_DISCHARGING.
| Returns | |
|---|---|
boolean |
|
Interfaces
Classes
- AsyncTask
- BaseBundle
- BatteryManager
- Binder
- Build
- Build.VERSION
- Build.VERSION_CODES
- Bundle
- CancellationSignal
- ConditionVariable
- CountDownTimer
- CpuUsageInfo
- Debug
- Debug.InstructionCount
- Debug.MemoryInfo
- DropBoxManager
- DropBoxManager.Entry
- Environment
- FileObserver
- Handler
- HandlerThread
- HardwarePropertiesManager
- LocaleList
- Looper
- MemoryFile
- Message
- MessageQueue
- Messenger
- Parcel
- ParcelFileDescriptor
- ParcelFileDescriptor.AutoCloseInputStream
- ParcelFileDescriptor.AutoCloseOutputStream
- ParcelUuid
- PatternMatcher
- PersistableBundle
- PowerManager
- PowerManager.WakeLock
- Process
- ProxyFileDescriptorCallback
- RecoverySystem
- RemoteCallbackList
- ResultReceiver
- StatFs
- StrictMode
- StrictMode.ThreadPolicy
- StrictMode.ThreadPolicy.Builder
- StrictMode.VmPolicy
- StrictMode.VmPolicy.Builder
- SystemClock
- TestLooperManager
- TokenWatcher
- Trace
- UserHandle
- UserManager
- VibrationEffect
- Vibrator
- WorkSource
Enums
Exceptions