1e41f4b71Sopenharmony_ci# @system.battery (电量信息) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci该模块提供充电状态及剩余电量的查询功能。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> - 从API Version 6开始不再维护,建议使用[`@ohos.batteryInfo`](js-apis-battery-info.md)替代。 7e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 导入模块 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```js 14e41f4b71Sopenharmony_ciimport {Battery, BatteryResponse } from '@kit.BasicServicesKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## Battery.getStatus 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_cigetStatus(options?: GetStatusOptions): void; 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci获取设备当前的充电状态及剩余电量。 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.PowerManager.BatteryManager.Lite 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**参数:** 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 29e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 30e41f4b71Sopenharmony_ci| options | [GetStatusOptions](#getstatusoptions) | 否 | 包含接口调用结果的对象。可选,默认为空。 | 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**示例:** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci```js 35e41f4b71Sopenharmony_ciBattery.getStatus({ 36e41f4b71Sopenharmony_ci success: (data: BatteryResponse) => { 37e41f4b71Sopenharmony_ci console.log('success get battery level:' + data.level); 38e41f4b71Sopenharmony_ci }, 39e41f4b71Sopenharmony_ci fail: (data: string, code: number) => { 40e41f4b71Sopenharmony_ci console.error('fail to get battery level code:' + code + ', data: ' + data); 41e41f4b71Sopenharmony_ci } 42e41f4b71Sopenharmony_ci}); 43e41f4b71Sopenharmony_ci``` 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci## GetStatusOptions 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci包含接口调用结果的对象。 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.PowerManager.BatteryManager.Lite 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 52e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ | 53e41f4b71Sopenharmony_ci| success | (data: [BatteryResponse](#batteryresponse)) => void | 否 | 接口调用成功的回调函数,data为[BatteryResponse](#batteryresponse)类型的返回值。 | 54e41f4b71Sopenharmony_ci| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。data为错误信息,code为错误码。 | 55e41f4b71Sopenharmony_ci| complete | () => void | 否 | 接口调用结束的回调函数。 | 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci## BatteryResponse 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci包含充电状态及剩余电量的对象。 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.PowerManager.BatteryManager.Lite 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| 参数名 | 类型 | 可读 | 可写 | 说明 | 64e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 65e41f4b71Sopenharmony_ci| charging | boolean | 是 | 否 | 当前电池是否在充电中。 | 66e41f4b71Sopenharmony_ci| level | number | 是 | 否 | 当前电池的电量,取值范围:0.00 - 1.00 。 | 67