my.getBatteryInfo asynchronously obtains the battery level and the charging state of the current device. No input parameters are required.
my.getBatteryInfo({
success: (res) => {
my.alert({
content: "Battery: " + res.level + "%, Charging: " + res.isCharging,
});
},
fail: (err) => {
my.alert({ content: "Inquiry failed: " + JSON.stringify(err) });
},
complete: () => {
console.log("Complete callback");
},
});
| Property | Type | Required | Description |
|---|---|---|---|
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (executed whether the call succeeds or fails). |
The incoming parameter is an Object with the following attributes:
| Property | Type | Description |
|---|---|---|
level | Number | Battery level of the current device (0–100). |
isCharging | Boolean | Whether the device is currently charging. |