UNPKG

4.99 kBMarkdownView Raw
1<!--
2# license: Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18-->
19
20# cordova-plugin-battery-status
21
22[![Build Status](https://travis-ci.org/apache/cordova-plugin-battery-status.svg)](https://travis-ci.org/apache/cordova-plugin-battery-status)
23
24This plugin provides an implementation of an old version of the [Battery Status Events API](http://www.w3.org/TR/2011/WD-battery-status-20110915/).
25
26It adds the following three `window` events:
27
28* batterystatus
29* batterycritical
30* batterylow
31
32## Installation
33
34 cordova plugin add cordova-plugin-battery-status
35
36## batterystatus
37
38This event fires when the percentage of battery charge changes by at
39least 1 percent, or if the device is plugged in or unplugged.
40
41The battery status handler is passed an object that contains two
42properties:
43
44- __level__: The percentage of battery charge (0-100). _(Number)_
45
46- __isPlugged__: A boolean that indicates whether the device is plugged in. _(Boolean)_
47
48Applications typically should use `window.addEventListener` to
49attach an event listener after the `deviceready` event fires.
50
51### Supported Platforms
52
53- Amazon Fire OS
54- iOS
55- Android
56- BlackBerry 10
57- Windows Phone 7 and 8
58- Windows (Windows Phone 8.1 only)
59- Tizen
60- Firefox OS
61- Browser
62
63### Android and Amazon Fire OS Quirks
64
65- Warning: the Android + Fire OS implementations are greedy and prolonged use will drain the user's battery.
66
67### Windows Phone 7 and 8 Quirks
68
69Windows Phone 7 does not provide native APIs to determine battery
70level, so the `level` property is unavailable. The `isPlugged`
71parameter _is_ supported.
72
73### Windows Quirks
74
75Windows Phone 8.1 does not support `isPlugged` parameter.
76The `level` parameter _is_ supported.
77
78### Browser Quirks
79
80Supported browsers are Chrome, Firefox and Opera.
81
82### Example
83
84 window.addEventListener("batterystatus", onBatteryStatus, false);
85
86 function onBatteryStatus(info) {
87 // Handle the online event
88 console.log("Level: " + info.level + " isPlugged: " + info.isPlugged);
89 }
90
91## batterycritical
92
93The event fires when the percentage of battery charge has reached the
94critical battery threshold. The value is device-specific.
95
96The `batterycritical` handler is passed an object that contains two
97properties:
98
99- __level__: The percentage of battery charge (0-100). _(Number)_
100
101- __isPlugged__: A boolean that indicates whether the device is plugged in. _(Boolean)_
102
103Applications typically should use `window.addEventListener` to attach
104an event listener once the `deviceready` event fires.
105
106### Supported Platforms
107
108- Amazon Fire OS
109- iOS
110- Android
111- BlackBerry 10
112- Tizen
113- Firefox OS
114- Windows (Windows Phone 8.1 only)
115- Browser
116
117### Windows Quirks
118
119Windows Phone 8.1 will fire `batterycritical` event regardless of plugged state as it is not supported.
120
121### Example
122
123 window.addEventListener("batterycritical", onBatteryCritical, false);
124
125 function onBatteryCritical(info) {
126 // Handle the battery critical event
127 alert("Battery Level Critical " + info.level + "%\nRecharge Soon!");
128 }
129
130### Browser Quirks
131
132Supported browsers are Chrome, Firefox and Opera.
133
134## batterylow
135
136The event fires when the percentage of battery charge has reached the
137low battery threshold, device-specific value.
138
139The `batterylow` handler is passed an object that contains two
140properties:
141
142- __level__: The percentage of battery charge (0-100). _(Number)_
143
144- __isPlugged__: A boolean that indicates whether the device is plugged in. _(Boolean)_
145
146Applications typically should use `window.addEventListener` to
147attach an event listener once the `deviceready` event fires.
148
149### Supported Platforms
150
151- Amazon Fire OS
152- iOS
153- Android
154- BlackBerry 10
155- Tizen
156- Firefox OS
157- Windows (Windows Phone 8.1 only)
158- Browser
159
160### Windows Quirks
161
162Windows Phone 8.1 will fire `batterylow` event regardless of plugged state as it is not supported.
163
164### Example
165
166 window.addEventListener("batterylow", onBatteryLow, false);
167
168 function onBatteryLow(info) {
169 // Handle the battery low event
170 alert("Battery Level Low " + info.level + "%");
171 }
172
173### Browser Quirks
174
175Supported browsers are Chrome, Firefox and Opera.