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