public class BatteryManager extends Object
Intent.ACTION_BATTERY_CHANGED
Intent, and
provides a method for querying battery and charging properties.Modifier and Type | Field and Description |
---|---|
static String |
ACTION_CHARGING
Sent when the device's battery has started charging (or has reached full charge
and the device is on power).
|
static 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.
|
static int |
BATTERY_HEALTH_COLD |
static int |
BATTERY_HEALTH_DEAD |
static int |
BATTERY_HEALTH_GOOD |
static int |
BATTERY_HEALTH_OVER_VOLTAGE |
static int |
BATTERY_HEALTH_OVERHEAT |
static int |
BATTERY_HEALTH_UNKNOWN |
static int |
BATTERY_HEALTH_UNSPECIFIED_FAILURE |
static int |
BATTERY_PLUGGED_AC
Power source is an AC charger.
|
static int |
BATTERY_PLUGGED_ANY |
static int |
BATTERY_PLUGGED_USB
Power source is a USB port.
|
static int |
BATTERY_PLUGGED_WIRELESS
Power source is wireless.
|
static int |
BATTERY_PROPERTY_CAPACITY
Remaining battery capacity as an integer percentage of total capacity
(with no fractional part).
|
static int |
BATTERY_PROPERTY_CHARGE_COUNTER
Battery capacity in microampere-hours, as an integer.
|
static int |
BATTERY_PROPERTY_CURRENT_AVERAGE
Average battery current in microamperes, as an integer.
|
static int |
BATTERY_PROPERTY_CURRENT_NOW
Instantaneous battery current in microamperes, as an integer.
|
static int |
BATTERY_PROPERTY_ENERGY_COUNTER
Battery remaining energy in nanowatt-hours, as a long integer.
|
static int |
BATTERY_STATUS_CHARGING |
static int |
BATTERY_STATUS_DISCHARGING |
static int |
BATTERY_STATUS_FULL |
static int |
BATTERY_STATUS_NOT_CHARGING |
static int |
BATTERY_STATUS_UNKNOWN |
static String |
EXTRA_CHARGE_COUNTER
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the charge counter present in the battery. |
static String |
EXTRA_HEALTH
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the current health constant. |
static String |
EXTRA_ICON_SMALL
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the resource ID of a small status bar icon
indicating the current battery state. |
static String |
EXTRA_INVALID_CHARGER
Extra for
Intent.ACTION_BATTERY_CHANGED :
Int value set to nonzero if an unsupported charger is attached
to the device. |
static String |
EXTRA_LEVEL
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer field containing the current battery level, from 0 to
EXTRA_SCALE . |
static String |
EXTRA_MAX_CHARGING_CURRENT
Extra for
Intent.ACTION_BATTERY_CHANGED :
Int value set to the maximum charging current supported by the charger in micro amperes. |
static String |
EXTRA_MAX_CHARGING_VOLTAGE
Extra for
Intent.ACTION_BATTERY_CHANGED :
Int value set to the maximum charging voltage supported by the charger in micro volts. |
static String |
EXTRA_PLUGGED
Extra for
Intent.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. |
static String |
EXTRA_PRESENT
Extra for
Intent.ACTION_BATTERY_CHANGED :
boolean indicating whether a battery is present. |
static String |
EXTRA_SCALE
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the maximum battery level. |
static String |
EXTRA_STATUS
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the current status constant. |
static String |
EXTRA_TECHNOLOGY
Extra for
Intent.ACTION_BATTERY_CHANGED :
String describing the technology of the current battery. |
static String |
EXTRA_TEMPERATURE
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the current battery temperature. |
static String |
EXTRA_VOLTAGE
Extra for
Intent.ACTION_BATTERY_CHANGED :
integer containing the current battery voltage level. |
Constructor and Description |
---|
BatteryManager() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static final String EXTRA_STATUS
Intent.ACTION_BATTERY_CHANGED
:
integer containing the current status constant.public static final String EXTRA_HEALTH
Intent.ACTION_BATTERY_CHANGED
:
integer containing the current health constant.public static final String EXTRA_PRESENT
Intent.ACTION_BATTERY_CHANGED
:
boolean indicating whether a battery is present.public static final String EXTRA_LEVEL
Intent.ACTION_BATTERY_CHANGED
:
integer field containing the current battery level, from 0 to
EXTRA_SCALE
.public static final String EXTRA_SCALE
Intent.ACTION_BATTERY_CHANGED
:
integer containing the maximum battery level.public static final String EXTRA_ICON_SMALL
Intent.ACTION_BATTERY_CHANGED
:
integer containing the resource ID of a small status bar icon
indicating the current battery state.public static final String EXTRA_PLUGGED
Intent.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.public static final String EXTRA_VOLTAGE
Intent.ACTION_BATTERY_CHANGED
:
integer containing the current battery voltage level.public static final String EXTRA_TEMPERATURE
Intent.ACTION_BATTERY_CHANGED
:
integer containing the current battery temperature.public static final String EXTRA_TECHNOLOGY
Intent.ACTION_BATTERY_CHANGED
:
String describing the technology of the current battery.public static final String EXTRA_INVALID_CHARGER
Intent.ACTION_BATTERY_CHANGED
:
Int value set to nonzero if an unsupported charger is attached
to the device.
public static final String EXTRA_MAX_CHARGING_CURRENT
Intent.ACTION_BATTERY_CHANGED
:
Int value set to the maximum charging current supported by the charger in micro amperes.
public static final String EXTRA_MAX_CHARGING_VOLTAGE
Intent.ACTION_BATTERY_CHANGED
:
Int value set to the maximum charging voltage supported by the charger in micro volts.
public static final String EXTRA_CHARGE_COUNTER
Intent.ACTION_BATTERY_CHANGED
:
integer containing the charge counter present in the battery.
public static final int BATTERY_STATUS_UNKNOWN
public static final int BATTERY_STATUS_CHARGING
public static final int BATTERY_STATUS_DISCHARGING
public static final int BATTERY_STATUS_NOT_CHARGING
public static final int BATTERY_STATUS_FULL
public static final int BATTERY_HEALTH_UNKNOWN
public static final int BATTERY_HEALTH_GOOD
public static final int BATTERY_HEALTH_OVERHEAT
public static final int BATTERY_HEALTH_DEAD
public static final int BATTERY_HEALTH_OVER_VOLTAGE
public static final int BATTERY_HEALTH_UNSPECIFIED_FAILURE
public static final int BATTERY_HEALTH_COLD
public static final int BATTERY_PLUGGED_AC
public static final int BATTERY_PLUGGED_USB
public static final int BATTERY_PLUGGED_WIRELESS
public static final int BATTERY_PLUGGED_ANY
public static final String ACTION_CHARGING
ACTION_DISCHARGING
. The current state can always
be retrieved with isCharging()
.public static final String ACTION_DISCHARGING
ACTION_CHARGING
. The current state can always
be retrieved with isCharging()
.public static final int BATTERY_PROPERTY_CHARGE_COUNTER
public static final int BATTERY_PROPERTY_CURRENT_NOW
public static final int BATTERY_PROPERTY_CURRENT_AVERAGE
public static final int BATTERY_PROPERTY_CAPACITY
public static final int BATTERY_PROPERTY_ENERGY_COUNTER
public boolean isCharging()
ACTION_CHARGING
and ACTION_DISCHARGING
.public int getIntProperty(int id)
id
- identifier of the requested propertypublic long getLongProperty(int id)
id
- identifier of the requested property