title | description |
---|---|
Battery Status |
Get events for device battery level. |
This plugin provides an implementation based on the W3C Battery Status Events API. The method navigator.getBattery() returns a promise with a BatteryManager object which has the following event handlers:
- onchargingchange
- onchargingtimechange
- ondischargingtimechange
- onlevelchange
phonegap plugin add phonegap-plugin-battery-status
The BatteryManager object has the following properties:
- level: The battery charge percentage (0-100). (Number)
- charging: A boolean that indicates whether the device is plugged in. (Boolean)
- chargingTime: The time remaining to fully charge the battery. (Number)
- dischargingTime: The time remaining for the battery level to come down to 0. (Number)
Fires when the device is plugged in or unplugged.
navigator.getBattery().then(function(battery) {
battery.onchargingchange = function() {
console.log(this.level);
};
});
Fires when the time required to charge the device changes.
navigator.getBattery().then(function(battery) {
console.log(battery.level);
battery.onchargingtimechange = function() {
console.log(this.level);
};
});
Fires when the time required to discharge the device changes.
navigator.getBattery().then(function(battery) {
battery.ondischargingtimechange = function() {
console.log(this.level);
};
});
Fires when the battery level of the device changes.
navigator.getBattery().then(function(battery) {
battery.onlevelchange = function() {
console.log(this.level);
};
});