• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.batteryInfo (Battery Information)
2
3The **batteryInfo** module provides APIs for querying the charger type, battery health status, and battery charging status.
4
5> **NOTE**
6>
7> 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.
8
9
10## Modules to Import
11
12```js
13import batteryInfo from '@ohos.batteryInfo';
14```
15
16## Attributes
17
18Describes battery information.
19
20**System capability**: SystemCapability.PowerManager.BatteryManager.Core
21
22| Name     | Type       | Readable| Writable|  Description    |
23| --------------- | ------------------- | ---- | ---- | ---------------------|
24| batterySOC                                | number                                         | Yes  | No  | Battery state of charge (SoC) of the device, in unit of percentage.                          |
25| chargingStatus                            | [BatteryChargeState](#batterychargestate)      | Yes  | No  | Battery charging status of the device.                              |
26| healthStatus                              | [BatteryHealthState](#batteryhealthstate)      | Yes  | No  | Battery health status of the device.                              |
27| pluggedType                               | [BatteryPluggedType](#batterypluggedtype)      | Yes  | No  | Charger type of the device.                            |
28| voltage                                   | number                                         | Yes  | No  | Battery voltage of the device, in unit of microvolt.                        |
29| technology                                | string                                         | Yes  | No  | Battery technology of the device.                              |
30| batteryTemperature                        | number                                         | Yes  | No  | Battery temperature of the device, in unit of 0.1°C.                   |
31| isBatteryPresent<sup>7+</sup>             | boolean                                        | Yes  | No  | Whether the battery is supported or present.                |
32| batteryCapacityLevel<sup>9+</sup>         | [BatteryCapacityLevel](#batterycapacitylevel9) | Yes  | No  | Battery level of the device.                              |
33| estimatedRemainingChargeTime<sup>9+</sup> | number                                         | Yes  | No  | Estimated time for fully charging the current device, in unit of milliseconds. This is a system API.         |
34| totalEnergy<sup>9+</sup>                  | number                                         | Yes  | No  | Total battery capacity of the device, in unit of mAh. This is a system API.  |
35| nowCurrent<sup>9+</sup>                   | number                                         | Yes  | No  | Battery current of the device, in unit of mA. This is a system API.      |
36| remainingEnergy<sup>9+</sup>              | number                                         | Yes  | No  | Remaining battery capacity of the device, in unit of mAh. This is a system API.|
37
38## BatteryPluggedType
39
40Enumerates charger types.
41
42**System capability**: SystemCapability.PowerManager.BatteryManager.Core
43
44| Name      | Value | Description             |
45| -------- | ---- | ----------------- |
46| NONE     | 0    | Unknown charger type.     |
47| AC       | 1    | AC charger.|
48| USB      | 2    | USB charger.  |
49| WIRELESS | 3    | Wireless charger.|
50
51## BatteryChargeState
52
53Enumerates charging states.
54
55**System capability**: SystemCapability.PowerManager.BatteryManager.Core
56
57| Name     | Value | Description           |
58| ------- | ---- | --------------- |
59| NONE    | 0    | Unknown state.    |
60| ENABLE  | 1    | The battery is being charged. |
61| DISABLE | 2    | The battery is not being charged. |
62| FULL    | 3    | The battery is fully charged.|
63
64## BatteryHealthState
65
66Enumerates battery health states.
67
68**System capability**: SystemCapability.PowerManager.BatteryManager.Core
69
70| Name         | Value | Description          |
71| ----------- | ---- | -------------- |
72| UNKNOWN     | 0    | Unknown state.   |
73| GOOD        | 1    | The battery is in the healthy state.  |
74| OVERHEAT    | 2    | The battery is overheated.  |
75| OVERVOLTAGE | 3    | The battery voltage is over high.  |
76| COLD        | 4    | The battery temperature is low.  |
77| DEAD        | 5    | The battery is dead.|
78
79## BatteryCapacityLevel<sup>9+</sup>
80
81Enumerates battery levels.
82
83**System capability**: SystemCapability.PowerManager.BatteryManager.Core
84
85| Name          | Value| Description                      |
86| -------------- | ------ | ---------------------------- |
87| LEVEL_FULL     | 1      | Full battery level.  |
88| LEVEL_HIGH     | 2      | High battery level.  |
89| LEVEL_NORMAL   | 3      | Normal battery level.|
90| LEVEL_LOW      | 4      | Low battery level.  |
91| LEVEL_WARNING  | 5      | Alarm battery level.|
92| LEVEL_CRITICAL | 6      | Ultra-low battery level.|
93| LEVEL_SHUTDOWN | 7      | Power-down battery level.|
94
95## CommonEventBatteryChangedKey<sup>9+</sup>
96
97Enumerates keys for querying the additional information about the **COMMON_EVENT_BATTERY_CHANGED** event.
98
99**System capability**: SystemCapability.PowerManager.BatteryManager.Core
100
101| Name                | Value| Description                                            |
102| -------------------- | ------ | -------------------------------------------------- |
103| EXTRA_SOC            | "soc" | Remaining battery level in percentage.                  |
104| EXTRA_CHARGE_STATE   | "chargeState" | Battery charging status of the device.                |
105| EXTRA_HEALTH_STATE   | "healthState" | Battery health status of the device.                |
106| EXTRA_PLUGGED_TYPE   | "pluggedType" | Type of the charger connected to the device.            |
107| EXTRA_VOLTAGE        | "voltage" | Battery voltage of the device.                    |
108| EXTRA_TECHNOLOGY     | "technology" | Battery technology of the device.                |
109| EXTRA_TEMPERATURE    | "temperature" | Battery temperature of the device.                    |
110| EXTRA_PRESENT        | "present" | Whether the battery is supported by the device or installed.|
111| EXTRA_CAPACITY_LEVEL | "capacityLevel" | Battery level of the device.                |
112