• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.batteryInfo (Battery Information)
2
3<!--Kit: Basic Services Kit-->
4<!--Subsystem: PowerManager-->
5<!--Owner: @zhang-yinglie; @volcano_wang-->
6<!--Designer: @wangyantian0-->
7<!--Tester: @alien0208-->
8<!--Adviser: @w_Machine_cc-->
9
10The **batteryInfo** module provides APIs for querying the charger type, battery health status, and battery charging status.
11
12> **NOTE**
13>
14> 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.
15
16
17## Modules to Import
18
19```js
20import {batteryInfo} from '@kit.BasicServicesKit';
21```
22
23## batteryInfo
24
25Describes battery information.
26
27**System capability**: SystemCapability.PowerManager.BatteryManager.Core
28
29| Name     | Type       | Read-Only| Optional|  Description    |
30| --------------- | ------------------- | ---- | ---- | ---------------------|
31| batterySOC                                | number                                         | Yes  | No  | Battery state of charge (SoC) of the device, in unit of percentage.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                          |
32| chargingStatus                            | [BatteryChargeState](#batterychargestate)      | Yes  | No  | Battery charging state of the current device.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                              |
33| healthStatus                              | [BatteryHealthState](#batteryhealthstate)      | Yes  | No  | Battery health status of the device.                              |
34| pluggedType                               | [BatteryPluggedType](#batterypluggedtype)      | Yes  | No  | Charger type of the device.                            |
35| voltage                                   | number                                         | Yes  | No  | Battery voltage of the device, in unit of microvolt.                        |
36| technology                                | string                                         | Yes  | No  | Battery technology of the device.                              |
37| batteryTemperature                        | number                                         | Yes  | No  | Battery temperature of the device, in unit of 0.1°C.                   |
38| isBatteryPresent<sup>7+</sup>             | boolean                                        | Yes  | No  | Whether the battery is supported or present. The value **true** means that the battery is supported or present; **false** means the opposite.<br>Default value: **false**.                |
39| batteryCapacityLevel<sup>9+</sup> | [BatteryCapacityLevel](#batterycapacitylevel9) | Yes       | No       | Battery level of the device. |
40| nowCurrent<sup>12+</sup> | number                                         | Yes       | No       | Battery current of the device, in unit of mA. |
41**Example**
42
43  ```ts
44  import {batteryInfo} from '@kit.BasicServicesKit';
45
46  let batterySOCInfo: number = batteryInfo.batterySOC;
47  console.info("The batterySOCInfo is: " + batterySOCInfo);
48
49  let chargingStatusInfo = batteryInfo.chargingStatus;
50  console.info("The chargingStatusInfo is: " + chargingStatusInfo);
51
52  let healthStatusInfo = batteryInfo.healthStatus;
53  console.info("The healthStatusInfo is: " + healthStatusInfo);
54
55  let pluggedTypeInfo = batteryInfo.pluggedType;
56  console.info("The pluggedTypeInfo is: " + pluggedTypeInfo);
57
58  let voltageInfo: number = batteryInfo.voltage;
59  console.info("The voltageInfo is: " + voltageInfo);
60
61  let technologyInfo: string = batteryInfo.technology;
62  console.info("The technologyInfo is: " + technologyInfo);
63
64  let batteryTemperatureInfo: number = batteryInfo.batteryTemperature;
65  console.info("The batteryTemperatureInfo is: " + batteryTemperatureInfo);
66
67  let isBatteryPresentInfo: boolean = batteryInfo.isBatteryPresent;
68  console.info("The isBatteryPresentInfo is: " + isBatteryPresentInfo);
69
70  let batteryCapacityLevelInfo = batteryInfo.batteryCapacityLevel;
71  console.info("The batteryCapacityLevelInfo is: " + batteryCapacityLevelInfo);
72
73  let nowCurrentInfo: number = batteryInfo.nowCurrent;
74  console.info("The nowCurrentInfo is: " + nowCurrentInfo);
75  ```
76
77## BatteryPluggedType
78
79Enumerates charger types.
80
81**System capability**: SystemCapability.PowerManager.BatteryManager.Core
82
83| Name      | Value | Description             |
84| -------- | ---- | ----------------- |
85| NONE     | 0    | Unknown charger type.     |
86| AC       | 1    | AC charger.|
87| USB      | 2    | USB charger.  |
88| WIRELESS | 3    | Wireless charger.|
89
90## BatteryChargeState
91
92Enumerates charging states.
93
94**Atomic service API**: This API can be used in atomic services since API version 12.
95
96**System capability**: SystemCapability.PowerManager.BatteryManager.Core
97
98| Name     | Value | Description           |
99| ------- | ---- | --------------- |
100| NONE    | 0    | Unknown state.    |
101| ENABLE  | 1    | The battery is being charged. |
102| DISABLE | 2    | The battery is not being charged. |
103| FULL    | 3    | The battery is fully charged.|
104
105## BatteryHealthState
106
107Enumerates battery health states.
108
109**System capability**: SystemCapability.PowerManager.BatteryManager.Core
110
111| Name         | Value | Description          |
112| ----------- | ---- | -------------- |
113| UNKNOWN     | 0    | Unknown state.   |
114| GOOD        | 1    | The battery is in the healthy state.  |
115| OVERHEAT    | 2    | The battery is overheated.  |
116| OVERVOLTAGE | 3    | The battery voltage is over high.  |
117| COLD        | 4    | The battery temperature is low.  |
118| DEAD        | 5    | The battery is dead.|
119
120## BatteryCapacityLevel<sup>9+</sup>
121
122Enumerates battery levels.
123
124**System capability**: SystemCapability.PowerManager.BatteryManager.Core
125
126| Name          | Value| Description                      |
127| -------------- | ------ | ---------------------------- |
128| LEVEL_FULL     | 1      | Full battery level.  |
129| LEVEL_HIGH     | 2      | High battery level.  |
130| LEVEL_NORMAL   | 3      | Normal battery level.|
131| LEVEL_LOW      | 4      | Low battery level.  |
132| LEVEL_WARNING  | 5      | Alarm battery level.|
133| LEVEL_CRITICAL | 6      | Ultra-low battery level.|
134| LEVEL_SHUTDOWN | 7      | Power-down battery level.|
135
136## CommonEventBatteryChangedKey<sup>9+</sup>
137
138Enumerates keys for querying the additional information about the **COMMON_EVENT_BATTERY_CHANGED** event.
139
140**System capability**: SystemCapability.PowerManager.BatteryManager.Core
141
142| Name                | Value| Description                                            |
143| -------------------- | ------ | -------------------------------------------------- |
144| EXTRA_SOC            | "soc" | Remaining battery level in percentage.                  |
145| EXTRA_CHARGE_STATE   | "chargeState" | Battery charging status of the device.                |
146| EXTRA_HEALTH_STATE   | "healthState" | Battery health status of the device.                |
147| EXTRA_PLUGGED_TYPE   | "pluggedType" | Type of the charger connected to the device.            |
148| EXTRA_VOLTAGE        | "voltage" | Battery voltage of the device.                    |
149| EXTRA_TECHNOLOGY     | "technology" | Battery technology of the device.                |
150| EXTRA_TEMPERATURE    | "temperature" | Battery temperature of the device.                    |
151| EXTRA_PRESENT        | "present" | Whether the battery is supported by the device or installed.|
152| EXTRA_CAPACITY_LEVEL | "capacityLevel" | Battery level of the device.                |
153