BatteryManager
open class BatteryManager
kotlin.Any | |
↳ | android.os.BatteryManager |
The BatteryManager class contains strings and constants used for values in the android.content.Intent#ACTION_BATTERY_CHANGED
Intent, and provides a method for querying battery and charging properties.
Summary
Constants | |
---|---|
static String |
Sent when the device's battery has started charging (or has reached full charge and the device is on power). |
static String |
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 | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int |
Power source is an AC charger. |
static Int |
Power source is dock. |
static Int |
Power source is a USB port. |
static Int |
Power source is wireless. |
static Int |
Remaining battery capacity as an integer percentage of total capacity (with no fractional part). |
static Int |
Battery capacity in microampere-hours, as an integer. |
static Int |
Average battery current in microamperes, as an integer. |
static Int |
Instantaneous battery current in microamperes, as an integer. |
static Int |
Battery remaining energy in nanowatt-hours, as a long integer. |
static Int |
Battery charge status, from a BATTERY_STATUS_* value. |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
static String |
Extra for |
Public methods | |
---|---|
open Long |
Compute an approximation for how much time (in milliseconds) remains until the battery is fully charged. |
open Int |
getIntProperty(id: Int) Return the value of a battery property of integer type. |
open Long |
getLongProperty(id: Int) Return the value of a battery property of long type If the platform does not provide the property queried, this value will be Long. |
open String? |
getStringProperty(id: Int) Return the value of a battery property of String type. |
open Boolean |
Return true if the battery is currently considered to be charging. |
Constants
ACTION_CHARGING
static val ACTION_CHARGING: String
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()
.
Value: "android.os.action.CHARGING"
ACTION_DISCHARGING
static val ACTION_DISCHARGING: String
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()
.
Value: "android.os.action.DISCHARGING"
BATTERY_HEALTH_OVER_VOLTAGE
static val BATTERY_HEALTH_OVER_VOLTAGE: Int
Value: 5
BATTERY_HEALTH_UNSPECIFIED_FAILURE
static val BATTERY_HEALTH_UNSPECIFIED_FAILURE: Int
Value: 6
BATTERY_PLUGGED_AC
static val BATTERY_PLUGGED_AC: Int
Power source is an AC charger.
Value: 1
BATTERY_PLUGGED_DOCK
static val BATTERY_PLUGGED_DOCK: Int
Power source is dock.
Value: 8
BATTERY_PLUGGED_USB
static val BATTERY_PLUGGED_USB: Int
Power source is a USB port.
Value: 2
BATTERY_PLUGGED_WIRELESS
static val BATTERY_PLUGGED_WIRELESS: Int
Power source is wireless.
Value: 4
BATTERY_PROPERTY_CAPACITY
static val BATTERY_PROPERTY_CAPACITY: Int
Remaining battery capacity as an integer percentage of total capacity (with no fractional part).
Value: 4
BATTERY_PROPERTY_CHARGE_COUNTER
static val BATTERY_PROPERTY_CHARGE_COUNTER: Int
Battery capacity in microampere-hours, as an integer.
Value: 1
BATTERY_PROPERTY_CURRENT_AVERAGE
static val BATTERY_PROPERTY_CURRENT_AVERAGE: Int
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.
Value: 3
BATTERY_PROPERTY_CURRENT_NOW
static val BATTERY_PROPERTY_CURRENT_NOW: Int
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.
Value: 2
BATTERY_PROPERTY_ENERGY_COUNTER
static val BATTERY_PROPERTY_ENERGY_COUNTER: Int
Battery remaining energy in nanowatt-hours, as a long integer.
Value: 5
BATTERY_PROPERTY_STATUS
static val BATTERY_PROPERTY_STATUS: Int
Battery charge status, from a BATTERY_STATUS_* value.
Value: 6
BATTERY_STATUS_NOT_CHARGING
static val BATTERY_STATUS_NOT_CHARGING: Int
Value: 4
EXTRA_BATTERY_LOW
static val EXTRA_BATTERY_LOW: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: Boolean field indicating whether the battery is currently considered to be low, that is whether a Intent#ACTION_BATTERY_LOW
broadcast has been sent.
Value: "battery_low"
EXTRA_CHARGING_STATUS
static val EXTRA_CHARGING_STATUS: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: Int value representing the battery charging status.
Value: "android.os.extra.CHARGING_STATUS"
EXTRA_CYCLE_COUNT
static val EXTRA_CYCLE_COUNT: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: Int value representing the battery charging cycle count.
Value: "android.os.extra.CYCLE_COUNT"
EXTRA_HEALTH
static val EXTRA_HEALTH: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer containing the current health constant.
Value: "health"
EXTRA_ICON_SMALL
static val EXTRA_ICON_SMALL: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer containing the resource ID of a small status bar icon indicating the current battery state.
Value: "icon-small"
EXTRA_LEVEL
static val EXTRA_LEVEL: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer field containing the current battery level, from 0 to EXTRA_SCALE
.
Value: "level"
EXTRA_PLUGGED
static val EXTRA_PLUGGED: String
Extra for android.content.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.
Value: "plugged"
EXTRA_PRESENT
static val EXTRA_PRESENT: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: boolean indicating whether a battery is present.
Value: "present"
EXTRA_SCALE
static val EXTRA_SCALE: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer containing the maximum battery level.
Value: "scale"
EXTRA_STATUS
static val EXTRA_STATUS: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer containing the current status constant.
Value: "status"
EXTRA_TECHNOLOGY
static val EXTRA_TECHNOLOGY: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: String describing the technology of the current battery.
Value: "technology"
EXTRA_TEMPERATURE
static val EXTRA_TEMPERATURE: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer containing the current battery temperature.
Value: "temperature"
EXTRA_VOLTAGE
static val EXTRA_VOLTAGE: String
Extra for android.content.Intent#ACTION_BATTERY_CHANGED
: integer containing the current battery voltage level.
Value: "voltage"
Public methods
computeChargeTimeRemaining
open fun computeChargeTimeRemaining(): Long
Compute an approximation for how much time (in milliseconds) remains until the battery is fully charged. Returns -1 if no time can be computed: either there is not enough current data to make a decision or the battery is currently discharging.
Return | |
---|---|
Long |
how much time is left, in milliseconds, until the battery is fully charged or -1 if the computation fails |
getIntProperty
open fun getIntProperty(id: Int): Int
Return the value of a battery property of integer type.
Parameters | |
---|---|
id |
Int: identifier of the requested property |
Return | |
---|---|
Int |
the property value. If the property is not supported or there is any other error, return (a) 0 if targetSdkVersion < VERSION_CODES.P or (b) Integer.MIN_VALUE if targetSdkVersion >= VERSION_CODES.P . |
getLongProperty
open fun getLongProperty(id: Int): Long
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 |
Return | |
---|---|
Long |
the property value, or Long.MIN_VALUE if not supported. |
getStringProperty
open fun getStringProperty(id: Int): String?
Return the value of a battery property of String type. If the platform does not provide the property queried, this value will be null.
Parameters | |
---|---|
id |
Int: identifier of the requested property. |
Return | |
---|---|
String? |
the property value, or null if not supported. |
isCharging
open fun isCharging(): Boolean
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
.