Cordova plugin to get battery level on demand for iOS.
- iOS (including iOS8)
- android
The plugin can be installed from git repository.
From master:
# ~~ from master branch ~~
cordova plugin add https://github.com/solo999/cordova-plugin-battery-level.git
- See CHANGELOG.md to get the full changelog for the plugin.
The plugin creates the object cordova.plugins.battery.level
with the following method:
battery.level.get [battery.level.isPluggedIn][is-plugged-in]
The plugin and its methods are not available before the deviceready event has been fired.
document.addEventListener('deviceready', function () {
// cordova.plugins.battery.level is now available
}, false);
The battery level can be accessed through the battery.level.get
interface.
The method takes a callback function as its argument which will be called with the battery level. Optional the scope of the callback function ca be defined through a second argument.
cordova.plugins.battery.level.get(function (battLevel) {
// console.log('battery level: ' + battLevel);
}, scope);
The isPluggedIn flag can be accessed through the battery.level.isPluggedIn
interface.
The method takes a callback function as its argument which will be called with the isPluggedIn flag. Optional the scope of the callback function ca be defined through a second argument.
cordova.plugins.battery.level.isPluggedIn(function (isPluggedIn) {
// console.log('device is ' + isPluggedIn ? 'plugged in' : 'plugged out');
}, scope);
This software is released under the Apache 2.0 License.
© 2013-2014 Polaris Telematics Ltd (HK). All rights reserved