1# @ohos.batteryInfo (电量信息)(系统接口) 2 3该模块主要提供电池状态和充放电状态的查询接口。 4 5> **说明:** 6> 7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9>当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.batteryInfo (电量信息)](js-apis-battery-info.md)。 10 11 12## 导入模块 13 14```js 15import batteryInfo from '@ohos.batteryInfo'; 16``` 17 18## batteryInfo.setBatteryConfig<sup>11+</sup> 19 20setBatteryConfig(sceneName: string, sceneValue: string): number 21 22按场景名称设置电池配置。 23 24**系统接口:** 此接口为系统接口。 25 26**系统能力:** SystemCapability.PowerManager.BatteryManager.Core 27 28**参数**: 29 30| 参数名 | 类型 | 必填 | 说明 | 31| ---------- | ------ | ---- | ------------ | 32| sceneName | string | 是 | 设置场景名称 | 33| sceneValue | string | 是 | 设置场景的值 | 34 35**返回值**: 36 37| 类型 | 说明 | 38| ------ | ---------------------------------------------------------- | 39| number | 返回设置充电结果。返回0表示设置成功,返回非0表示设置失败。 | 40 41**错误码:** 42 43以下错误码的详细介绍请参见[电量信息错误码](errorcode-battery-info.md)。 44 45| 错误码ID | 错误信息 | 46|---------|---------| 47| 4900101 | If connecting to the service failed. | 48 49**示例**: 50 51 ```ts 52 import batteryInfo from '@ohos.batteryInfo'; 53 54 let sceneName = 'xxx'; 55 let sceneValue = '0'; 56 let result = batteryInfo.setBatteryConfig(sceneName, sceneValue); 57 58 console.info("The result is: " + result); 59 ``` 60 61## batteryInfo.getBatteryConfig<sup>11+</sup> 62 63getBatteryConfig(sceneName: string): string 64 65按场景名称查询电池配置。 66 67**系统接口:** 此接口为系统接口。 68 69**系统能力:** SystemCapability.PowerManager.BatteryManager.Core 70 71**参数**: 72 73| 参数名 | 类型 | 必填 | 说明 | 74| --------- | ------ | ---- | ------------ | 75| sceneName | string | 是 | 设置场景名称 | 76 77**返回值**: 78 79| 类型 | 说明 | 80| ------ | ------------------------------ | 81| string | 返回电池充电配置,否则返回""。 | 82 83**错误码:** 84 85以下错误码的详细介绍请参见[电量信息错误码](errorcode-battery-info.md)。 86 87| 错误码ID | 错误信息 | 88|---------|---------| 89| 4900101 | If connecting to the service failed. | 90 91**示例**: 92 93 ```ts 94 import batteryInfo from '@ohos.batteryInfo'; 95 96 let sceneName = 'xxx'; 97 let result = batteryInfo.getBatteryConfig(sceneName); 98 99 console.info("The result is: " + result); 100 ``` 101 102## batteryInfo.isBatteryConfigSupported<sup>11+</sup> 103 104isBatteryConfigSupported(sceneName: string): boolean 105 106检查是否按场景名称启用电池配置。 107 108**系统接口:** 此接口为系统接口。 109 110**系统能力:** SystemCapability.PowerManager.BatteryManager.Core 111 112**参数**: 113 114| 参数名 | 类型 | 必填 | 说明 | 115| --------- | ------ | ---- | ------------ | 116| sceneName | string | 是 | 设置场景名称 | 117 118**返回值**: 119 120| 类型 | 说明 | 121| ------- | ------------------------------------------------- | 122| boolean | 如果设备支持充电场景,则返回true,否则返回false。 | 123 124**错误码:** 125 126以下错误码的详细介绍请参见[电量信息错误码](errorcode-battery-info.md)。 127 128| 错误码ID | 错误信息 | 129|---------|---------| 130| 4900101 | If connecting to the service failed. | 131 132**示例**: 133 134 ```ts 135 import batteryInfo from '@ohos.batteryInfo'; 136 137 let sceneName = 'xxx'; 138 let result = batteryInfo.isBatteryConfigSupported(sceneName); 139 140 console.info("The result is: " + result); 141 ``` 142 143## 属性 144 145描述电池信息。 146 147**系统能力**:SystemCapability.PowerManager.BatteryManager.Core 148 149| 名称 | 类型 | 可读 | 可写 | 说明 | 150| --------------- | ------------------- | ---- | ---- | ---------------------| 151| estimatedRemainingChargeTime<sup>9+</sup> | number | 是 | 否 | 表示当前设备充满电的预估时间,单位毫秒。此接口为系统接口。 | 152| totalEnergy<sup>9+</sup> | number | 是 | 否 | 表示当前设备电池的总容量,单位毫安时。此接口为系统接口。 | 153| nowCurrent<sup>9+</sup> | number | 是 | 否 | 表示当前设备电池的电流,单位毫安。此接口为系统接口。 | 154| remainingEnergy<sup>9+</sup> | number | 是 | 否 | 表示当前设备电池的剩余容量,单位毫安时。此接口为系统接口。 | 155 156