This package has been deprecated

Author message:

This package is deprecated, see https://blog.phonegap.com/update-for-customers-using-phonegap-and-phonegap-build-cc701c77502c

phonegap-plugin-battery-status
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

title: Battery Status description: Get events for device battery level.

phonegap-plugin-battery-status

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

Installation

phonegap plugin add phonegap-plugin-battery-status

Status object

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)

onchargingchange event

Fires when the device is plugged in or unplugged.

Example

    navigator.getBattery().then(function(battery) {
        battery.onchargingchange = function() {
            console.log(this.level);
        };
    });

onchargingtimechange event

Fires when the time required to charge the device changes.

Example

    navigator.getBattery().then(function(battery) {
        console.log(battery.level);
        battery.onchargingtimechange = function() {
            console.log(this.level);
        };
    });

ondischargingtimechange event

Fires when the time required to discharge the device changes.

Example

    navigator.getBattery().then(function(battery) {
        battery.ondischargingtimechange = function() {
            console.log(this.level);
        };
    });

onlevelchange event

Fires when the battery level of the device changes.

Example

    navigator.getBattery().then(function(battery) {
        battery.onlevelchange = function() {
        console.log(this.level);
        };
    });

Quirks: The onchargingtimechange and the ondischargingtimechange events and the chargingtime and dischargingTime properties are not supported on iOS.

Dependents (0)

Package Sidebar

Install

npm i phonegap-plugin-battery-status

Weekly Downloads

1

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • purplecabbage
  • macdonst
  • vishalmishra