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

PropertyType

Required

Description
successFunctionNoThe callback function for a successful API call.
failFunctionNoThe callback function for a failed API call.
completeFunctionNoThe callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails.

Success callback function

PropertyTypeDescription
levelIntThe battery level of the current device. 
isChargingBooleanThis property indicates whether the device is charging.