Book Image

Phonegap Essentials

By : Ivan Turkovic
Book Image

Phonegap Essentials

By: Ivan Turkovic

Overview of this book

Table of Contents (15 chapters)

The Battery Status plugin

One of the important needs of an application is to know the current battery state so it can handle data correctly, and to ensure the battery does not run out before being able to save crucial data information, or take a crucial action.

There are three events that are especially useful for developing applications; they are related to the battery charge and determining when the battery state is critical, so you know when to save or back up data.

To install the following plugin, you need to run the following command:

phonegap plugin add cordova-plugin-battery-status

With this plugin, you need to run examples on the physical device since the simulator does not provide data for it. There are alternatives available, such as the Chrome browser with the Ripple plugin, but we will explore this in detail in the final chapter.

The Battery Status event

This event is emitted every time the battery charge changes by at least one percent or when the device is plugged or unplugged...