This topic describes the JavaScript APIs of WVBattery. You can refer to this topic when you create HTML5 apps or Miniapps. You can use the JavaScript APIs of WVBattery to obtain the battery level.
WVBattery.getBatteryInfo
This API is available only in WindVane Android 1.0.3.4 or later.
Asynchronously obtains the battery level.
Input parameters
No input parameters exist.
Callback parameters
Parameters for a success callback:
[
string]level: the current battery level.[
string]isCharging: specifies whether the battery is charging.[
string]chargingType: the charging type. ac indicates that the device is charged by using the power supply. usb indicates that the device is charged via the USB cable. wire indicates that the device is charged by using a wireless charging method.
Parameters for a failure callback:
[
string]msg: the error message.
window.WindVane.call('WVBattery', 'getBatteryInfo', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});WVBattery.getBatteryInfoSync
This API is available only in WindVane Android 1.0.3.4 or later.
Synchronously obtains the battery level.
Input parameters
No input parameters exist.
Callback parameters
Parameters for a success callback:
[
string]level: the current battery level.[
string]isCharging: specifies whether the battery is charging.[
string]chargingType: the charging type. ac indicates that the device is charged by using the power supply. usb indicates that the device is charged via the USB cable. wire indicates that the device is charged using a wireless charging method.
Parameters for a failure callback:
[
string]msg: the error message.
window.WindVane.call('WVBattery', 'getBatteryInfoSync', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});