batterylow

The event fires when the battery has reached the low level threshold.

window.addEventListener("batterylow", yourCallbackFunction, false);

Details

The event fires when the percentage of battery charge has reached the low battery threshold, device-specific value.

The batterylow handler is passed an object that contains two properties:

  • level: The percentage of battery charge (0-100). (Number)

  • isPlugged: A boolean that indicates whether the device is plugged in. (Boolean)

Applications typically should use document.addEventListener to attach an event listener once the [deviceready](events.deviceready.html) event fires.

Supported Platforms

  • Amazon Fire OS
  • iOS
  • Android
  • BlackBerry 10
  • Tizen

Quick Example

window.addEventListener("batterylow", onBatteryLow, false);

function onBatteryLow(info) {
    // Handle the battery low event
    alert("Battery Level Low " + info.level + "%");
}

Full Example

<!DOCTYPE html>
<html>
  <head>
    <title>Device Ready Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    //
    function onDeviceReady() {
        window.addEventListener("batterylow", onBatteryLow, false);
    }

    // Handle the batterylow event
    //
    function onBatteryLow(info) {
        alert("Battery Level Low " + info.level + "%");
    }

    </script>
  </head>
  <body onload="onLoad()">
  </body>
</html>