Updated README.md, added colour coding for examples

pull/1/head
Max Bassett 8 years ago committed by GitHub
parent 827ea04e1c
commit f121af93c3

@ -25,107 +25,113 @@ Usage
### window.powerManagement.acquire(successCallback, failureCallback)
Acquire a wakelock by calling this.
window.powerManagement.acquire(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
```js
window.powerManagement.acquire(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
```
### window.powerManagement.dim(successCallback, failureCallback)
This acquires a partial wakelock, allowing the screen to be dimmed.
window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
```js
window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
```
### window.powerManagement.release(successCallback, failureCallback)
Release the wakelock. It's important to do this when you're finished with the wakelock, to avoid unnecessary battery drain.
window.powerManagement.release(function() {
console.log('Wakelock released');
}, function() {
console.log('Failed to release wakelock');
});
```js
window.powerManagement.release(function() {
console.log('Wakelock released');
}, function() {
console.log('Failed to release wakelock');
});
```
### [Android Only] window.powerManagement.setReleaseOnPause(enabled, successCallback, failureCallback)
By default, the plugin will automatically release a wakelock when your app is paused (e.g. when the screen is turned off, or the user switches to another app). It will reacquire the wakelock upon app resume. If you would prefer to disable this behaviour, you can use this function.
```js
window.powerManagement.setReleaseOnPause(false, function() {
console.log('Set successfully');
}, function() {
console.log('Failed to set');
});
```
window.powerManagement.setReleaseOnPause(false, function() {
console.log('Set successfully');
}, function() {
console.log('Failed to set');
});
### [Android Only, API >= 23] window.powerManagement.isDeviceIdleMode(successCallback, failureCallback)
As of Android 6.0.0+, Android now has an extra power management feature called 'Doze'. This feature disables most device
components (network connection, GPS, etc.) when it is asleep for an extended period of time and is then placed in an 'idle' state.
To check to see if the device is in this state, you can use the following function:
// 'state' is either 1 (in idle) or 0 (not in idle)
window.powerManagement.isDeviceIdleMode(function(state) {
if (state === 1) {
console.log('Device IS in idle mode.');
}
else {
console.log('Device IS NOT in idle mode.');
}
}, function() {
console.log('Failed to check the device's idle state.');
});
```js
// 'state' is either 1 (in idle) or 0 (not in idle)
window.powerManagement.isDeviceIdleMode(function(state) {
if (state === 1) {
console.log('Device IS in idle mode.');
}
else {
console.log('Device IS NOT in idle mode.');
}
}, function() {
console.log('Failed to check the device's idle state.');
});
```
### [Android Only, API >= 23] window.powerManagement.addAppToBatteryWhitelist(successCallback, failureCallback)
As of Android 6.0.0+, Android now has an extra power management feature called 'Doze'. This feature disables most device
components (network connection, GPS, etc.) when it is asleep for an extended period of time and is then placed in an 'idle' state. Adding the app to the battery optimization whitelist can circumvent some of these issues.
To add the app that uses this plugin to the device's battery optimization whitelist, use the following function:
window.powerManagement.addAppToBatteryWhitelist(function() {
console.log('A dialog has popped up asking you to accept adding the app to the whitelist.');
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
```js
window.powerManagement.addAppToBatteryWhitelist(function() {
console.log('A dialog has popped up asking you to accept adding the app to the whitelist.');
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
```
### [Android Only, API >= 23] window.powerManagement.isIgnoringBatteryOptimizations(successCallback, failureCallback)
As of Android 6.0.0+, Android now has an extra power management feature called 'Doze'. This feature disables most device
components (network connection, GPS, etc.) when it is asleep for an extended period of time and is then placed in an 'idle' state.
To check to see if the app that uses this plugin is on the device's battery optimization whitelist, use the following function:
window.powerManagement.isIgnoringBatteryOptimizations(function(result) {
if (result === 1) {
console.log('This app IS on the device's battery optimization whitelist.');
}
else {
console.log('This app IS NOT on the device's battery optimization whitelist.');
}
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
```js
window.powerManagement.isIgnoringBatteryOptimizations(function(result) {
if (result === 1) {
console.log('This app IS on the device's battery optimization whitelist.');
}
else {
console.log('This app IS NOT on the device's battery optimization whitelist.');
}
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
```
This function can be use in conjunction with the `window.powerManagement.addAppToBatteryWhitelist` above. Example:
window.powerManagement.isIgnoringBatteryOptimizations(function(result) {
// If the app isn't on the battery whitelist, open the dialog to add it
if (result !== 1) {
window.powerManagement.addAppToBatteryWhitelist(function() {
console.log('A dialog has popped up asking you to accept adding the app to the whitelist.');
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
}
else {
console.log('This app IS NOT on the device's battery optimization whitelist.');
}
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
```js
window.powerManagement.isIgnoringBatteryOptimizations(function(result) {
// If the app isn't on the battery whitelist, open the dialog to add it
if (result !== 1) {
window.powerManagement.addAppToBatteryWhitelist(function() {
console.log('A dialog has popped up asking you to accept adding the app to the whitelist.');
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
}
else {
console.log('This app IS NOT on the device's battery optimization whitelist.');
}
}, function() {
console.log('Failed to add the app to the device's battery optimization whitelist.');
});
```
Note that in all the above examples, all callbacks are optional.
License

Loading…
Cancel
Save