Battery Status Plugin

Tested Version: 2.0.3

This document is based on the original Cordova docs available at Cordova Docs.

Plugin ID

cordova-plugin-battery-status

Adding the Plugin

In order to use this plugin, please enable Battery plugin in Monaca Cloud IDE.

API Reference

Status object

All events in this plugin return an object with the following properties:

Property

Type

Description

level

Number

The battery charge percentage (0-100)

isPlugged

Boolean

Indicates whether the device is plugged in

batterystatus event

Fires when the battery charge percentage changes by at least 1 percent, or when the device is plugged in or unplugged. Returns an object containing battery status.

Example

window.addEventListener("batterystatus", onBatteryStatus, false);

function onBatteryStatus(status) {
    console.log("Level: " + status.level + " isPlugged: " + status.isPlugged);
}

Supported Platforms

  • iOS

  • Android

Quirks: Android

The Android implementations are greedy and prolonged use will drain the device's battery.

batterylow event

Fires when the battery charge percentage reaches the low charge threshold. This threshold value is device-specific. Returns an object containing battery status.

Example

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

function onBatteryLow(status) {
    alert("Battery Level Low " + status.level + "%");
}

Supported Platforms

  • iOS

  • Android

batterycritical event

Fires when the battery charge percentage reaches the critical charge threshold. This threshold value is device-specific. Returns an object containing battery status.

Example

window.addEventListener("batterycritical", onBatteryCritical, false);

function onBatteryCritical(status) {
    alert("Battery Level Critical " + status.level + "%\nRecharge Soon!");
}

Supported Platforms

  • iOS

  • Android

See Also:

Last updated