The WVBattery JavaScript APIs allow you to retrieve device battery information, such as the battery level and charging status, in HTML5 apps and miniapps.
WVBattery.getBatteryInfo
This API is available only in Windvane for Android 1.0.3.4 or later.
Retrieves the battery level, charging status, and charging type of the device.
Input parameters
None.
Callback parameters
The success callback returns the following parameters:
-
[
string] level: The current battery level. -
[
string] isCharging: The charging status of the device. -
[
string] chargingType: The charging type. Valid values areacfor AC charging,usbfor USB charging, andwirelessfor wireless charging.
The failure callback returns the following parameter:
-
[
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 for Android 1.0.3.4 or later.
Synchronously retrieves the battery level, charging status, and charging type of the device.
Input parameters
None.
Callback parameters
The success callback returns the following parameters:
-
[
string] level: The current battery level. -
[
string] isCharging: The charging status of the device. -
[
string] chargingType: The charging type. Valid values areacfor AC charging,usbfor USB charging, andwirelessfor wireless charging.
The failure callback returns the following parameter:
-
[
string] msg: The error message.
window.WindVane.call('WVBattery', 'getBatteryInfoSync', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});