1e41f4b71Sopenharmony_ci# @ohos.batteryInfo (电量信息)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci该模块主要提供电池状态和充放电状态的查询接口。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```js
13e41f4b71Sopenharmony_ciimport {batteryInfo} from '@kit.BasicServicesKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## 属性
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci描述电池信息。
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.PowerManager.BatteryManager.Core
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| 名称      | 类型        | 可读 | 可写 |  说明     |
23e41f4b71Sopenharmony_ci| --------------- | ------------------- | ---- | ---- | ---------------------|
24e41f4b71Sopenharmony_ci| batterySOC                                | number                                         | 是   | 否   | 表示当前设备剩余电池电量百分比。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                           |
25e41f4b71Sopenharmony_ci| chargingStatus                            | [BatteryChargeState](#batterychargestate)      | 是   | 否   | 表示当前设备电池的充电状态。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                               |
26e41f4b71Sopenharmony_ci| healthStatus                              | [BatteryHealthState](#batteryhealthstate)      | 是   | 否   | 表示当前设备电池的健康状态。                               |
27e41f4b71Sopenharmony_ci| pluggedType                               | [BatteryPluggedType](#batterypluggedtype)      | 是   | 否   | 表示当前设备连接的充电器类型。                             |
28e41f4b71Sopenharmony_ci| voltage                                   | number                                         | 是   | 否   | 表示当前设备电池的电压,单位微伏。                         |
29e41f4b71Sopenharmony_ci| technology                                | string                                         | 是   | 否   | 表示当前设备电池的技术型号。                               |
30e41f4b71Sopenharmony_ci| batteryTemperature                        | number                                         | 是   | 否   | 表示当前设备电池的温度,单位0.1摄氏度。                    |
31e41f4b71Sopenharmony_ci| isBatteryPresent<sup>7+</sup>             | boolean                                        | 是   | 否   | 表示当前设备是否支持电池或者电池是否在位。                 |
32e41f4b71Sopenharmony_ci| batteryCapacityLevel<sup>9+</sup>         | [BatteryCapacityLevel](#batterycapacitylevel9) | 是   | 否   | 表示当前设备电池电量的等级。                                                  
33e41f4b71Sopenharmony_ci| nowCurrent<sup>12+</sup>                  | number                                         | 是   | 否   | 表示当前设备电池的电流,单位毫安。                        |         
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**示例**:
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci  ```ts
38e41f4b71Sopenharmony_ci  import {batteryInfo} from '@kit.BasicServicesKit';
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci  let batterySOCInfo: number = batteryInfo.batterySOC;
41e41f4b71Sopenharmony_ci  console.info("The batterySOCInfo is: " + batterySOCInfo);
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci  let chargingStatusInfo = batteryInfo.chargingStatus;
44e41f4b71Sopenharmony_ci  console.info("The chargingStatusInfo is: " + chargingStatusInfo);
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci  let healthStatusInfo = batteryInfo.healthStatus;
47e41f4b71Sopenharmony_ci  console.info("The healthStatusInfo is: " + healthStatusInfo);
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci  let pluggedTypeInfo = batteryInfo.pluggedType;
50e41f4b71Sopenharmony_ci  console.info("The pluggedTypeInfo is: " + pluggedTypeInfo);
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci  let voltageInfo: number = batteryInfo.voltage;
53e41f4b71Sopenharmony_ci  console.info("The voltageInfo is: " + voltageInfo);
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci  let technologyInfo: string = batteryInfo.technology;
56e41f4b71Sopenharmony_ci  console.info("The technologyInfo is: " + technologyInfo);
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci  let batteryTemperatureInfo: number = batteryInfo.batteryTemperature;
59e41f4b71Sopenharmony_ci  console.info("The batteryTemperatureInfo is: " + batteryTemperatureInfo);
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci  let isBatteryPresentInfo: boolean = batteryInfo.isBatteryPresent;
62e41f4b71Sopenharmony_ci  console.info("The isBatteryPresentInfo is: " + isBatteryPresentInfo);
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci  let batteryCapacityLevelInfo = batteryInfo.batteryCapacityLevel;
65e41f4b71Sopenharmony_ci  console.info("The batteryCapacityLevelInfo is: " + batteryCapacityLevelInfo);
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci  let nowCurrentInfo: number = batteryInfo.nowCurrent;
68e41f4b71Sopenharmony_ci  console.info("The nowCurrentInfo is: " + nowCurrentInfo);
69e41f4b71Sopenharmony_ci  ```
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci## BatteryPluggedType
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci表示连接的充电器类型的枚举。
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.PowerManager.BatteryManager.Core
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci| 名称       | 值  | 说明              |
78e41f4b71Sopenharmony_ci| -------- | ---- | ----------------- |
79e41f4b71Sopenharmony_ci| NONE     | 0    | 表示未获取到连接充电器类型。      |
80e41f4b71Sopenharmony_ci| AC       | 1    | 表示连接的充电器类型为交流充电器。 |
81e41f4b71Sopenharmony_ci| USB      | 2    | 表示连接的充电器类型为USB。   |
82e41f4b71Sopenharmony_ci| WIRELESS | 3    | 表示连接的充电器类型为无线充电器。 |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci## BatteryChargeState
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci表示电池充电状态的枚举。
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.PowerManager.BatteryManager.Core
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| 名称      | 值  | 说明            |
93e41f4b71Sopenharmony_ci| ------- | ---- | --------------- |
94e41f4b71Sopenharmony_ci| NONE    | 0    | 表示电池充电状态未知。     |
95e41f4b71Sopenharmony_ci| ENABLE  | 1    | 表示电池充电状态为使能状态。  |
96e41f4b71Sopenharmony_ci| DISABLE | 2    | 表示电池充电状态为停止状态。  |
97e41f4b71Sopenharmony_ci| FULL    | 3    | 表示电池充电状态为已充满状态。 |
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci## BatteryHealthState
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci表示电池健康状态的枚举。
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.PowerManager.BatteryManager.Core
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| 名称          | 值  | 说明           |
106e41f4b71Sopenharmony_ci| ----------- | ---- | -------------- |
107e41f4b71Sopenharmony_ci| UNKNOWN     | 0    | 表示电池健康状态未知。    |
108e41f4b71Sopenharmony_ci| GOOD        | 1    | 表示电池健康状态为正常。   |
109e41f4b71Sopenharmony_ci| OVERHEAT    | 2    | 表示电池健康状态为过热。   |
110e41f4b71Sopenharmony_ci| OVERVOLTAGE | 3    | 表示电池健康状态为过压。   |
111e41f4b71Sopenharmony_ci| COLD        | 4    | 表示电池健康状态为低温。   |
112e41f4b71Sopenharmony_ci| DEAD        | 5    | 表示电池健康状态为僵死状态。 |
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci## BatteryCapacityLevel<sup>9+</sup>
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci表示电池电量等级的枚举。
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.PowerManager.BatteryManager.Core
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci| 名称           | 值 | 说明                       |
121e41f4b71Sopenharmony_ci| -------------- | ------ | ---------------------------- |
122e41f4b71Sopenharmony_ci| LEVEL_FULL     | 1      | 表示电池电量等级为满电量。   |
123e41f4b71Sopenharmony_ci| LEVEL_HIGH     | 2      | 表示电池电量等级为高电量。   |
124e41f4b71Sopenharmony_ci| LEVEL_NORMAL   | 3      | 表示电池电量等级为正常电量。 |
125e41f4b71Sopenharmony_ci| LEVEL_LOW      | 4      | 表示电池电量等级为低电量。   |
126e41f4b71Sopenharmony_ci| LEVEL_WARNING  | 5      | 表示电池电量等级为告警电量。 |
127e41f4b71Sopenharmony_ci| LEVEL_CRITICAL | 6      | 表示电池电量等级为极低电量。 |
128e41f4b71Sopenharmony_ci| LEVEL_SHUTDOWN | 7      | 表示电池电量等级为关机电量。 |
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci## CommonEventBatteryChangedKey<sup>9+</sup>
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci表示COMMON_EVENT_BATTERY_CHANGED通用事件附加信息的查询键。
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.PowerManager.BatteryManager.Core
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci| 名称                 | 值 | 说明                                             |
137e41f4b71Sopenharmony_ci| -------------------- | ------ | -------------------------------------------------- |
138e41f4b71Sopenharmony_ci| EXTRA_SOC            | "soc" | 表示剩余电池电量百分比的查询键。                   |
139e41f4b71Sopenharmony_ci| EXTRA_CHARGE_STATE   | "chargeState" | 表示当前设备电池充电状态的查询键。                 |
140e41f4b71Sopenharmony_ci| EXTRA_HEALTH_STATE   | "healthState" | 表示当前设备电池健康状态的查询键。                 |
141e41f4b71Sopenharmony_ci| EXTRA_PLUGGED_TYPE   | "pluggedType" | 表示当前设备连接的充电器类型的查询键。             |
142e41f4b71Sopenharmony_ci| EXTRA_VOLTAGE        | "voltage" | 表示当前设备电池电压的查询键。                     |
143e41f4b71Sopenharmony_ci| EXTRA_TECHNOLOGY     | "technology" | 表示当前设备电池技术型号的查询键。                 |
144e41f4b71Sopenharmony_ci| EXTRA_TEMPERATURE    | "temperature" | 表示当前设备电池温度的查询键。                     |
145e41f4b71Sopenharmony_ci| EXTRA_PRESENT        | "present" | 表示当前设备是否支持电池或者电池是否在位的查询键。 |
146e41f4b71Sopenharmony_ci| EXTRA_CAPACITY_LEVEL | "capacityLevel" | 表示当前设备电池电量等级的查询键。                 |
147