Presentation is loading. Please wait.

Presentation is loading. Please wait.

Phonegap Bridge – Battery API CIS 136 Building Mobile Apps 1.

Similar presentations


Presentation on theme: "Phonegap Bridge – Battery API CIS 136 Building Mobile Apps 1."— Presentation transcript:

1 Phonegap Bridge – Battery API CIS 136 Building Mobile Apps 1

2 Battery Status Plug-in org.apache.cordova.battery-status 2  a means for web developers to programmatically determine the battery status of the hosting device and whether the device is plugged in or not  without knowing the battery status of a device, you are designing the web application with the assumption there is sufficient battery level for the task at hand  battery of a device may exhaust faster than expected if apps are unable to make decisions based on the battery status  given knowledge of the battery status, web developers are able to craft web content and applications which are power- efficient, thereby leading to improved user experience

3 Battery Status Plug-in 3  Battery Status events can be used to defer or scale back work when the device is not plugged in or is low on battery  Ex:  In an advanced application, like an email app, the app can check the server for new email every few seconds if the device is plugged in, but do so less frequently if the device is not plugged in or is low on battery  In an advanced application, like a note keeper, the app could monitor the battery level and save changes before the battery runs out to prevent data loss

4 Battery Status Attributes 4  isPlugged (Boolean)  whether the device is plugged in  Level (float)  Represents how much of the internal power source remains, scaled from 0 to 100 (null if no juice)  Status (string)  the battery status of the hosting device, scaled from critical to ok

5 Battery Status Attributes 5  Critical  Low  OK  null - unable to report the battery's level

6 Battery Status Event 6  BatteryStatus event is triggered when  isPlugged changes its value, or  level changes by at least 1, or  status changes its value  This event fires when the percentage of battery charge changes by at least 1 percent, or if the device is plugged in or unplugged

7 Battery Status Example 7 window.addEventListener("batterystatus", onBatteryStatus, false); function onBatteryStatus(info) console.log("Level: " + info.level + " isPlugged: " + info.isPlugged); } o The battery status handler is passed an object that contains two properties: o level: The percentage of battery charge (0-100) o isPlugged: A boolean that indicates whether the device is plugged in o use an EventListener to attach an event handler after the deviceready event fires

8 Battery Critical 8  The event fires when the percentage of battery charge has reached the critical battery threshold  The value is device-specific

9 Battery Critical Example 9  The batterycritical handler is passed an object that contains two properties:  level: The percentage of battery charge (0-100)  isPlugged: A boolean that indicates whether the device is plugged in window.addEventListener("batterycritical", onBatteryCritical, false); function onBatteryCritical(info) { alert("Battery Level Critical " + info.level + "%\nRecharge Soon!"); }

10 Battery Low 10  This event fires when the percentage of battery charge has reached the low battery threshold  device-specific value

11 Battery Low Example 11  The batterylow handler is passed an object that contains two properties:  level: The percentage of battery charge (0-100)  isPlugged: A boolean that indicates whether the device is plugged in window.addEventListener("batterylow", onBatteryLow, false); function onBatteryLow(info) { alert("Battery Level Low " + info.level + "%"); }


Download ppt "Phonegap Bridge – Battery API CIS 136 Building Mobile Apps 1."

Similar presentations


Ads by Google