- 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.
batterycritical
The event fires when the battery has reached the critical level threshold.
window.addEventListener("batterycritical", yourCallbackFunction, false);
Details
The event fires when the percentage of battery charge has reached the critical battery threshold. The value is device-specific.
The batterycritical
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 window.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("batterycritical", onBatteryCritical, false);
function onBatteryCritical(info) {
// Handle the battery critical event
alert("Battery Level Critical " + info.level + "%\nRecharge Soon!");
}
Full Example
<!DOCTYPE html>
<html>
<head>
<title>Battery Critical 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("batterycritical", onBatteryCritical, false);
}
// Handle the batterycritical event
//
function onBatteryCritical(info) {
alert("Battery Level Critical " + info.level + "%\nRecharge Soon!");
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>