Skip to content

robindepege/cordova-plugin-battery-level

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-battery-level

Cordova plugin to get battery level on demand for iOS.

Overview

  1. Supported Platforms
  2. Installation
  3. ChangeLog
  4. Using the plugin

Supported Platforms

  • iOS (including iOS8)
  • android

Installation

The plugin can be installed from git repository.

Local development environment

From master:

# ~~ from master branch ~~
cordova plugin add https://github.com/solo999/cordova-plugin-battery-level.git

ChangeLog

  • See CHANGELOG.md to get the full changelog for the plugin.

Using the plugin

The plugin creates the object cordova.plugins.battery.level with the following method:

battery.level.get [battery.level.isPluggedIn][is-plugged-in]

Plugin initialization

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);

Get the battery level

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);

Check if device is plugged in

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);

License

This software is released under the Apache 2.0 License.

© 2013-2014 Polaris Telematics Ltd (HK). All rights reserved

About

Cordova plugin to get battery status on demand

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 47.6%
  • Java 27.9%
  • JavaScript 24.5%