FileDocCategorySizeDatePackage
BatteryManager.javaAPI DocAndroid 5.1 API8195Thu Mar 12 22:22:10 GMT 2015android.os

BatteryManager

public class BatteryManager extends Object
The BatteryManager class contains strings and constants used for values in the {@link android.content.Intent#ACTION_BATTERY_CHANGED} Intent, and provides a method for querying battery and charging properties.

Fields Summary
public static final String
EXTRA_STATUS
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: integer containing the current status constant.
public static final String
EXTRA_HEALTH
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: integer containing the current health constant.
public static final String
EXTRA_PRESENT
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: boolean indicating whether a battery is present.
public static final String
EXTRA_LEVEL
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: integer field containing the current battery level, from 0 to {@link #EXTRA_SCALE}.
public static final String
EXTRA_SCALE
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: integer containing the maximum battery level.
public static final String
EXTRA_ICON_SMALL
Extra for {@link android.content.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
Extra for {@link 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.
public static final String
EXTRA_VOLTAGE
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: integer containing the current battery voltage level.
public static final String
EXTRA_TEMPERATURE
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: integer containing the current battery temperature.
public static final String
EXTRA_TECHNOLOGY
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: String describing the technology of the current battery.
public static final String
EXTRA_INVALID_CHARGER
Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: Int value set to nonzero if an unsupported charger is attached to the device. {@hide}
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
Power source is an AC charger.
public static final int
BATTERY_PLUGGED_USB
Power source is a USB port.
public static final int
BATTERY_PLUGGED_WIRELESS
Power source is wireless.
public static final int
BATTERY_PLUGGED_ANY
public static final int
BATTERY_PROPERTY_CHARGE_COUNTER
Battery capacity in microampere-hours, as an integer.
public static final 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.
public static final 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.
public static final int
BATTERY_PROPERTY_CAPACITY
Remaining battery capacity as an integer percentage of total capacity (with no fractional part).
public static final int
BATTERY_PROPERTY_ENERGY_COUNTER
Battery remaining energy in nanowatt-hours, as a long integer.
private android.os.IBatteryPropertiesRegistrar
mBatteryPropertiesRegistrar
Constructors Summary
Methods Summary
public intgetIntProperty(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.

param
id identifier of the requested property
return
the property value, or Integer.MIN_VALUE if not supported.

        return (int)queryProperty(id);
    
public longgetLongProperty(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.

param
id identifier of the requested property
return
the property value, or Long.MIN_VALUE if not supported.

        return queryProperty(id);
    
private longqueryProperty(int id)
Query a battery property from the batteryproperties service. Returns the requested value, or Long.MIN_VALUE if property not supported on this system or on other error.


                                  
        
        long ret;

        if (mBatteryPropertiesRegistrar == null) {
            IBinder b = ServiceManager.getService("batteryproperties");
            mBatteryPropertiesRegistrar =
                IBatteryPropertiesRegistrar.Stub.asInterface(b);

            if (mBatteryPropertiesRegistrar == null)
                return Long.MIN_VALUE;
        }

        try {
            BatteryProperty prop = new BatteryProperty();

            if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0)
                ret = prop.getLong();
            else
                ret = Long.MIN_VALUE;
        } catch (RemoteException e) {
            ret = Long.MIN_VALUE;
        }

        return ret;