1# @ohos.batteryInfo (Battery Information) (System API)
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>This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.batteryInfo (Battery Information)](js-apis-battery-info.md).
10
11
12## Modules to Import
13
14```js
15import {batteryInfo} from '@kit.BasicServicesKit';
16```
17
18## batteryInfo.setBatteryConfig<sup>11+</sup>
19
20setBatteryConfig(sceneName: string, sceneValue: string): number
21
22Sets the battery configuration based on the specified scenario.
23
24**System API**: This is a system API.
25
26**System capability**: SystemCapability.PowerManager.BatteryManager.Core
27
28**Parameters**
29
30| Name    | Type  | Mandatory| Description        |
31| ---------- | ------ | ---- | ------------ |
32| sceneName  | string | Yes  | Scenario name. The value must be a string.|
33| sceneValue | string | Yes  | Scenario value. The value must be a string.|
34
35**Return value**
36
37| Type  | Description                                                      |
38| ------ | ---------------------------------------------------------- |
39| number | Operation result. The value **0** indicates that the operation is successful, and a non-zero value indicates the opposite.|
40
41**Error codes**
42
43For details about the error codes, see [Battery Information Error Codes](errorcode-battery-info.md).
44
45| ID  | Error Message   |
46|---------|---------|
47| 4900101 | Failed to connect to the service. |
48| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
49| 202     | Permission verification failed. A non-system application calls a system API. |
50
51**Example**
52
53  ```ts
54  import {batteryInfo} from '@kit.BasicServicesKit';
55
56  let sceneName = 'xxx';
57  let sceneValue = '0';
58  let result = batteryInfo.setBatteryConfig(sceneName, sceneValue);
59
60  console.info("The result is: " + result);
61  ```
62
63## batteryInfo.getBatteryConfig<sup>11+</sup>
64
65getBatteryConfig(sceneName: string): string
66
67Obtains the battery configuration based on the specified scenario.
68
69**System API**: This is a system API.
70
71**System capability**: SystemCapability.PowerManager.BatteryManager.Core
72
73**Parameters**
74
75| Name   | Type  | Mandatory| Description        |
76| --------- | ------ | ---- | ------------ |
77| sceneName | string | Yes  | Scenario name. The value must be a string.|
78
79**Return value**
80
81| Type  | Description                          |
82| ------ | ------------------------------ |
83| string | Operation result. The battery configuration is returned if the operation is successful. Otherwise, **""** is returned.|
84
85**Error codes**
86
87For details about the error codes, see [Battery Information Error Codes](errorcode-battery-info.md).
88
89| ID  | Error Message   |
90|---------|---------|
91| 4900101 | Failed to connect to the service. |
92| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
93| 202     | Permission verification failed. A non-system application calls a system API. |
94
95**Example**
96
97  ```ts
98  import {batteryInfo} from '@kit.BasicServicesKit';
99
100  let sceneName = 'xxx';
101  let result = batteryInfo.getBatteryConfig(sceneName);
102
103  console.info("The result is: " + result);
104  ```
105
106## batteryInfo.isBatteryConfigSupported<sup>11+</sup>
107
108isBatteryConfigSupported(sceneName: string): boolean
109
110Checks whether the battery configuration is enabled based on the specified scenario.
111
112**System API**: This is a system API.
113
114**System capability**: SystemCapability.PowerManager.BatteryManager.Core
115
116**Parameters**
117
118| Name   | Type  | Mandatory| Description        |
119| --------- | ------ | ---- | ------------ |
120| sceneName | string | Yes  | Scenario name. The value must be a string.|
121
122**Return value**
123
124| Type   | Description                                             |
125| ------- | ------------------------------------------------- |
126| boolean | Operation result. The value **true** indicates that the charging scenario is supported, and the value **false** indicates the opposite.|
127
128**Error codes**
129
130For details about the error codes, see [Battery Information Error Codes](errorcode-battery-info.md).
131
132| ID  | Error Message   |
133|---------|---------|
134| 4900101 | Failed to connect to the service. |
135| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
136| 202     | Permission verification failed. A non-system application calls a system API. |
137
138**Example**
139
140  ```ts
141  import {batteryInfo} from '@kit.BasicServicesKit';
142
143  let sceneName = 'xxx';
144  let result = batteryInfo.isBatteryConfigSupported(sceneName);
145
146  console.info("The result is: " + result);
147  ```
148
149## Attributes
150
151Describes battery information.
152
153**System capability**: SystemCapability.PowerManager.BatteryManager.Core
154
155| Name     | Type       | Readable| Writable|  Description    |
156| --------------- | ------------------- | ---- | ---- | ---------------------|
157| estimatedRemainingChargeTime<sup>9+</sup> | number                                         | Yes  | No  | Estimated time for fully charging the current device, in unit of milliseconds. This is a system API.         |
158| totalEnergy<sup>9+</sup>                  | number                                         | Yes  | No  | Total battery capacity of the device, in unit of mAh. This is a system API.  |
159| remainingEnergy<sup>9+</sup>              | number                                         | Yes  | No  | Remaining battery capacity of the device, in unit of mAh. This is a system API.|
160
161**Example**
162  ```ts
163  import {batteryInfo} from '@kit.BasicServicesKit';
164
165  let estimatedRemainingChargeTimeInfo: number = batteryInfo.estimatedRemainingChargeTime;
166  console.info("The estimatedRemainingChargeTimeInfo is: " + estimatedRemainingChargeTimeInfo);
167
168  let totalEnergyInfo: number = batteryInfo.totalEnergy;
169  console.info("The totalEnergyInfo is: " + totalEnergyInfo);
170
171  let remainingEnergyInfo: number = batteryInfo.remainingEnergy;
172  console.info("The remainingEnergyInfo is: " + remainingEnergyInfo);
173  ```
174