Plugin for Cordova (3.0+)
This code is from https://github.com/phonegap/phonegap-plugins/tree/master/Android/PowerManagement by Wolfgang Koller, edited by Kevin Frey, and put together with the directory structure and plugin.xml file by Adam Harris.
The PowerManagement plugin offers access to the devices power-management functionality. It should be used for applications which keep running for a long time without any user interaction.
For details on power functionality see:
- Android: PowerManager
- iOS: idleTimerDisabled
- WindowsPhone: UserIdleDetectionMode
Install with the Phonegap CLI:
phonegap local plugin install https://github.com/aharris88/phonegap-powerManagement-plugin.git
Also, make sure that you have the phonegap device plugin installed or it won't work:
phonegap local plugin install org.apache.cordova.device
Feel free to contribute any fixes, updates, or new features. If you notice anything wrong or have any requests, please add an issue.
Possible contributions:
- Add ability to keep wifi awake #3
You might want to set up a variable to keep track of whether or not the wake lock is on:
var wakelocked = false;
Then, you can turn on the wake lock like this. Inside the callback function, you can do whatever you want:
powerManagement.acquireWakeLock(function() {
wakelocked = true;
});
Similarly, you can turn off the wake lock:
powerManagement.releaseWakeLock(function() {
wakelocked = false;
});