@ohos.batteryInfo (Battery Information)

The batteryInfo module provides APIs for querying the charger type, battery health status, and battery charging status.

NOTE

The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import {batteryInfo} from '@kit.BasicServicesKit';

Constants

Describes battery information.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Name Type Read-Only Description
batterySOC number Yes Battery state of charge (SoC) of the device, in unit of percentage, which ranges from 0 to 100.
Atomic service API: This API can be used in atomic services since API version 12.
chargingStatus BatteryChargeState Yes Battery charging state of the current device.
Atomic service API: This API can be used in atomic services since API version 12.
healthStatus BatteryHealthState Yes Battery health status of the device.
pluggedType BatteryPluggedType Yes Charger type of the device.
voltage number Yes Battery voltage of the device, in unit of microvolt.
technology string Yes Battery technology of the device.
batteryTemperature number Yes Battery temperature of the device, in unit of 0.1°C.
isBatteryPresent7+ boolean Yes Whether the battery is supported or present. The value true means that the battery is supported or present; false means the opposite.
Default value: false.
batteryCapacityLevel9+ BatteryCapacityLevel Yes Battery level of the device.
nowCurrent12+ number Yes Battery current of the device, in unit of mA.

Example

import {batteryInfo} from '@kit.BasicServicesKit';

let batterySOCInfo: number = batteryInfo.batterySOC;
console.info("The batterySOCInfo is: " + batterySOCInfo);

let chargingStatusInfo = batteryInfo.chargingStatus;
console.info("The chargingStatusInfo is: " + chargingStatusInfo);

let healthStatusInfo = batteryInfo.healthStatus;
console.info("The healthStatusInfo is: " + healthStatusInfo);

let pluggedTypeInfo = batteryInfo.pluggedType;
console.info("The pluggedTypeInfo is: " + pluggedTypeInfo);

let voltageInfo: number = batteryInfo.voltage;
console.info("The voltageInfo is: " + voltageInfo);

let technologyInfo: string = batteryInfo.technology;
console.info("The technologyInfo is: " + technologyInfo);

let batteryTemperatureInfo: number = batteryInfo.batteryTemperature;
console.info("The batteryTemperatureInfo is: " + batteryTemperatureInfo);

let isBatteryPresentInfo: boolean = batteryInfo.isBatteryPresent;
console.info("The isBatteryPresentInfo is: " + isBatteryPresentInfo);

let batteryCapacityLevelInfo = batteryInfo.batteryCapacityLevel;
console.info("The batteryCapacityLevelInfo is: " + batteryCapacityLevelInfo);

let nowCurrentInfo: number = batteryInfo.nowCurrent;
console.info("The nowCurrentInfo is: " + nowCurrentInfo);

BatteryPluggedType

Enumerates charger types.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Name Value Description
NONE 0 Unknown charger type.
AC 1 AC charger.
USB 2 USB charger.
WIRELESS 3 Wireless charger.

BatteryChargeState

Enumerates charging states.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Name Value Description
NONE 0 The battery is not being charged.
ENABLE 1 The battery is being charged.
DISABLE 2 The battery charging is stopped.
FULL 3 The battery is fully charged.

BatteryHealthState

Enumerates battery health states.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Name Value Description
UNKNOWN 0 Unknown state.
GOOD 1 The battery is in the healthy state.
OVERHEAT 2 The battery is overheated.
OVERVOLTAGE 3 The battery voltage is over high.
COLD 4 The battery temperature is low.
DEAD 5 The battery is dead.

BatteryCapacityLevel9+

Enumerates battery levels.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Name Value Description
LEVEL_NONE23+ 0 Unknown battery level.
LEVEL_FULL 1 Full battery level.
LEVEL_HIGH 2 High battery level.
LEVEL_NORMAL 3 Normal battery level.
LEVEL_LOW 4 Low battery level.
LEVEL_WARNING 5 Alarm battery level.
LEVEL_CRITICAL 6 Ultra-low battery level.
LEVEL_SHUTDOWN 7 Power-down battery level.

CommonEventBatteryChangedKey9+

Enumerates keys for querying the additional information about the COMMON_EVENT_BATTERY_CHANGED event.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Name Value Description
EXTRA_SOC "soc" Remaining battery level in percentage.
EXTRA_CHARGE_STATE "chargeState" Battery charging status of the device.
EXTRA_HEALTH_STATE "healthState" Battery health status of the device.
EXTRA_PLUGGED_TYPE "pluggedType" Type of the charger connected to the device.
EXTRA_VOLTAGE "voltage" Battery voltage of the device.
EXTRA_TECHNOLOGY "technology" Battery technology of the device.
EXTRA_TEMPERATURE "temperature" Battery temperature of the device.
EXTRA_PRESENT "present" Whether the battery is supported by the device or installed.
EXTRA_CAPACITY_LEVEL "capacityLevel" Battery level of the device.