- Accelerometer
- Camera
- Capture
- Compass
- Connection
- Contacts
- Device
- Events
- File
- Geolocation
- Globalization
- InAppBrowser
- Media
- Notification
- Splashscreen
- Storage
- Overview
- Platform Guides
- The Cordova Command-line Interface
- Command-Line Usage
- Privacy Guide
- Upgrading Guides
- Project Settings
- Plugin Development Guide
- Domain Whitelist Guide
- Embedding WebView
This version of the documentation is outdated!
Click here for the latest released version.
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
- iOS
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- 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-x.x.x.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>