Skip to content

angel1st/cordova-plugin-battery-status-ondemand

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-battery-status-ondemand

Cordova plugin to get battery status on demand.

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/angel1st/cordova-plugin-battery-status-ondemand.git

Using the plugin

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

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

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 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(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.isPluggedIn(function (isPluggedIn) {
// console.log('device is ' + isPluggedIn ? 'plugged in' : 'plugged out');
}, scope);

Check battery status

The third method returns and object {level: batteryLevel, isPlugged: isDevicePlugged}. Basically, this method provides two above methods information at once. It is available via cordova.plugins.battery.level.status interface.
The method takes a callback function as its argument which will return status object. Optional the scope of the callback function ca be defined through a second argument.

cordova.plugins.battery.status(function (battStatus) {
// console.log('battery status: ' + JSON.stringify(battStatus));
}, scope);

License

This software is released under the Apache 2.0 License.

© 2018 Angel Todorov. All rights reserved

About

Cordova plugin to get battery status on demand

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Objective-C 45.7%
  • Java 35.7%
  • JavaScript 18.6%