Receive if the background mode is enabled

This commit is contained in:
Sebastián Katzer 2014-12-14 13:52:38 +01:00
parent cbed556154
commit fc6e6cf51d
3 changed files with 32 additions and 4 deletions

View File

@ -1,15 +1,16 @@
## ChangeLog
#### Version 0.6.1 (not yet released)
- [enhancement:] Set default settings through `setDefaults`.
- [enhancement:] New method `isEnabled`
- [bugfix:] Events caused thread collision.
#### Version 0.6.0 (14.12.2014)
- [feature:] Android support
- [feature:] Get default settings through `getDefaults`.
- [feature:] Change Android notification through `configure`.
- [feature:] `onactivate`, `ondeactivate` and `onfailure` callbacks.
- [___change___:] Disabled by default
- [enhancement:] Get default settings through `getDefaults`.
- [enhancement:] iOS does not require user permissions, internet connection and geo location anymore.
#### Version 0.5.0 (13.02.2014)

View File

@ -61,7 +61,7 @@ cordova plugin rm de.appplant.cordova.plugin.background-mode
### PhoneGap Build
Add the following xml to your config.xml to always use the latest version of this plugin:
```xml
<gap:plugin name="de.appplant.cordova.plugin.background-mode" version="0.6.0" source="plugins.cordova.io" />
<gap:plugin name="de.appplant.cordova.plugin.background-mode" version="0.6.0" source="plugins.cordova.io" />
```
More informations can be found [here][PGB_plugin].
@ -69,8 +69,9 @@ More informations can be found [here][PGB_plugin].
## ChangeLog
#### Version 0.6.1 (not yet released)
- [feature:] Get default settings through `getDefaults`.
- [feature:] Set default settings through `setDefaults`.
- [enhancement:] Set default settings through `setDefaults`.
- [enhancement:] New method `isEnabled`
- [bugfix:] Events caused thread collision.
#### Further informations
- The former `plugin.backgroundMode` namespace has been deprecated and will be removed with the next major release.
@ -85,6 +86,7 @@ The plugin creates the object ```cordova.plugins.backgroundMode``` with the fol
1. [backgroundMode.enable][enable]
2. [backgroundMode.disable][disable]
3. [backgroundMode.isEnabled][is_enabled]
3. [backgroundMode.getDefaults][android_specifics]
4. [backgroundMode.setDefaults][android_specifics]
2. [backgroundMode.configure][android_specifics]
@ -122,6 +124,13 @@ The background mode can be disabled through the `backgroundMode.disable` interfa
cordova.plugins.backgroundMode.disable();
```
### Receive if the background mode is enabled
The `backgroundMode.isActivated` interface can be used to get the information if the background mode is enabled or disabled.
```javascript
var enabled = cordova.plugins.backgroundMode.isEnabled();
```
### Get informed when the background mode has been activated
The `backgroundMode.onactivate` interface can be used to get notified when the background mode has been activated.

View File

@ -41,6 +41,13 @@ channel.onCordovaReady.subscribe(function () {
});
/**
* @private
*
* Flag indicated if the mod is enabled.
*/
exports._isEnabled = true;
/**
* @private
*
@ -60,6 +67,7 @@ exports._defaults = {
* for the next time.
*/
exports.enable = function () {
this._isEnabled = true;
cordova.exec(null, null, 'BackgroundMode', 'enable', []);
};
@ -68,6 +76,7 @@ exports.enable = function () {
* will not stay awake while in background.
*/
exports.disable = function () {
this._isEnabled = false;
cordova.exec(null, null, 'BackgroundMode', 'disable', []);
};
@ -115,6 +124,15 @@ exports.configure = function (options) {
}
};
/**
* If the mode is enabled or not.
*
* @return {Boolean}
*/
exports.isEnabled = function () {
return this._isEnabled;
};
/**
* Called when the background mode has been activated.
*/