I have a phonegap-bootstrap project on GitHub , a demo application written in PhoneGap 2.9. I placed event handlers for each event supported by PhoneGap. All of them work without any problems, except in cases related to the battery.
I was more than sure that this was due to a lack of permission, but it turned out to be wrong.
So ... Can someone tell me what is wrong with the following code:
var app = { init: function() { document.addEventListener('deviceready', app.deviceReadyHandler, false); app.writeEventLog('app.init();'); }, deviceReadyHandler: function() { document.addEventListener('batterylow', app.batteryLowHandler, false); document.addEventListener('batterystatus', app.batteryStatusHandler, false); document.addEventListener('batterycritical', app.batteryCriticalHandler, false); }, batteryLowHandler: function(info){app.batteryHandler('low', info);}, batteryStatusHandler: function(info){app.batteryHandler('status', info);}, batteryCriticalHandler: function(info){app.batteryHandler('critical', info);}, batteryHandler: function(type, info) { $('#lblBatteryLevel').html(info.level + '%'); $('#lblBatteryPlugged').html((info.isPlugged) ? 'yes' : 'no'); app.writeEventLog('app.battery' + event + 'Handler(level = ' + info.level +', isPlugged = ' + info.isPlugged + ');'); } } app.init();
For some reason, apart from my imagination, the PhoneGap Build app does not fire battery events. And only those related to the battery.
Battery events never fire, and the code inside the "global" ( batteryHandler ) never runs, so lblBatteryLevel and lblBatteryPlugged divs remain at their initial values ββ("[wait]").
And all other event handlers are encoded in exactly the same way. Declared in deviceReadyHandler :
document.addEventListener('pause', app.pauseHandler, false); document.addEventListener('resume', app.resumeHandler, false); document.addEventListener('online', app.onlineHandler, false); document.addEventListener('offline', app.offlineHandler, false); document.addEventListener('menubutton', app.menuButtonHandler, false); document.addEventListener('searchbutton', app.searchButtonHandler, false);
And then only logging events are determined:
pauseHandler: function(){app.writeEventLog('app.pauseHandler();');}, resumeHandler: function(){app.writeEventLog('app.resumeHandler();');}, onlineHandler: function(){app.writeEventLog('app.onlineHandler();');}, offlineHandler: function(){app.writeEventLog('app.offlineHandler();');}, menuButtonHandler: function(){app.writeEventLog('app.menuButtonHandler();');}, searchButtonHandler: function(){app.writeEventLog('app.searchButtonHandler();');},
All of them work, except for those associated with the battery.
I was more than sure that this was due to a lack of permission, but I checked three times that the line <feature name="http://api.phonegap.com/1.0/battery"/> fits in my config.xml file.
I tried asking guys in the PhoneGap Build Get Satisfaction forum, but didnβt get any advice what might be wrong.
I created jsFiddle where the HTML part contains my entire config.xml file and the Javascript part contains most of the battery related Javascript parts. Maybe someone has time reviewing it. I cannot find errors there, and the battery related code still does not work.