02 手机电量模块 - MiEcosystem/miot-plugin-sdk GitHub Wiki
手机的电量
Export: public
Doc_name: 手机电量模块
Doc_index: 2
Doc_directory: system
Example
import {System} from "miot"
...
System.battery.getBatteryInfo().then(res => {//return result})
...
-
miot/system
-
~IBattery
-
.getBatteryInfo() ⇒
[ 'Promise' ].<object>
-
.getBatteryInfo() ⇒
-
~IBattery
Kind: inner interface of miot/system
获取设备电量信息
Kind: instance method of IBattery
Returns: [ 'Promise' ].<object>
- res:
成功时:{"code":0, "data":xxx},data.level:string,设备电量,取值范围0-100,data.isCharging:boolean,是否正在充电中
失败时:{"code":-1, "message":"xxx" };
Since: 10043
Example
System.battery.getBatteryInfo().then((res) => {
if (res && res.data) {
alert(`getBatteryInfo success,level:${ res.data.level },isCharging:${ res.data.isCharging }`);
} else {
alert(`getBatteryInfo fail,${ JSON.stringify(res) }`);
}
}).catch((error) => {
alert(`getBatteryInfo fail,${ JSON.stringify(error) }`);
});