my.getBatteryInfo
Use this API to asynchronously obtain the battery level and the charging state of the current device. No parameters are required.
Sample Code
copy
my.getBatteryInfo({
success: (res) => {
my.alert({ content: 'System information:' + JSON.stringify(res), });
console.log({ content: 'System information:' + JSON.stringify(res), });
},
fail: (error) => {
my.alert({ content: 'Inquiry failed' + JSON.stringify(error), });
},
complete: () => {
my.alert({ title: 'Complete callback', });
},
})
Parameters
Property | Type | Required | Description |
success | Function | No | The callback function for a successful API call. |
fail | Function | No | The callback function for a failed API call. |
complete | Function | No | The callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails. |
Success callback function
Property | Type | Description |
level | Int | The battery level of the current device. |
isCharging | Boolean | This property indicates whether the device is charging. |