• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Battery Info
2
3> **NOTE**<br>
4> 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.
5
6The Battery Info module provides APIs for querying the charger type, battery health status, and battery charging status.
7
8
9## Modules to Import
10
11```js
12import batteryInfo from '@ohos.batteryInfo';
13```
14
15## System Capabilities
16
17SystemCapability.PowerManager.BatteryManager
18
19## Attributes
20
21Describes battery information.
22
23| Name                          | Type                                      | Readable | Writable | Description                                                  |
24| ----------------------------- | ----------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
25| batterySOC                    | number                                    | Yes      | No       | Battery state of charge (SoC) of the current device, in unit of percentage. |
26| chargingStatus                | [BatteryChargeState](#batterychargestate) | Yes      | No       | Battery charging state of the current device.                |
27| healthStatus                  | [BatteryHealthState](#batteryhealthstate) | Yes      | No       | Battery health state of the current device.                  |
28| pluggedType                   | [BatteryPluggedType](#batterypluggertype) | Yes      | No       | Charger type of the current device.                          |
29| voltage                       | number                                    | Yes      | No       | Battery voltage of the current device, in unit of microvolt. |
30| technology                    | string                                    | Yes      | No       | Battery technology of the current device.                    |
31| batteryTemperature            | number                                    | Yes      | No       | Battery temperature of the current device, in unit of 0.1°C. |
32| isBatteryPresent<sup>7+</sup> | boolean                                   | Yes      | No       | Whether the battery is supported or present.                 |
33
34**Example**
35
36```js
37import batteryInfo from '@ohos.batteryInfo';
38var batterySoc = batteryInfo.batterySOC;
39```
40
41
42## BatteryPluggedType
43
44Enumerates charger types.
45
46| Name     | Default Value | Description      |
47| -------- | ------------- | ---------------- |
48| NONE     | 0             | Unknown type     |
49| AC       | 1             | AC charger       |
50| USB      | 2             | USB charger      |
51| WIRELESS | 3             | Wireless charger |
52
53
54## BatteryChargeState
55
56Enumerates charging states.
57
58| Name    | Default Value | Description                       |
59| ------- | ------------- | --------------------------------- |
60| NONE    | 0             | Unknown state.                    |
61| ENABLE  | 1             | The battery is being charged.     |
62| DISABLE | 2             | The battery is not being charged. |
63| FULL    | 3             | The battery is fully charged.     |
64
65
66## BatteryHealthState
67
68Enumerates battery health states.
69
70| Name        | Default 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