mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-25 08:44:54 +00:00
parent
0b9854e1bc
commit
270abbff02
@ -1,4 +1,7 @@
|
||||
## ChangeLog
|
||||
#### Version 0.6.3 (not yet released)
|
||||
- [feature:] Silent mode for Android
|
||||
|
||||
#### Version 0.6.2 (14.12.2014)
|
||||
- [bugfix:] Type error
|
||||
- [bugfix:] Wrong default values for `isEnabled` and `isActive`.
|
||||
|
18
README.md
18
README.md
@ -68,16 +68,13 @@ More informations can be found [here][PGB_plugin].
|
||||
|
||||
|
||||
## ChangeLog
|
||||
#### Version 0.6.3 (not yet released)
|
||||
- [feature:] Silent mode for Android
|
||||
|
||||
#### Version 0.6.2 (14.12.2014)
|
||||
- [bugfix:] Type error
|
||||
- [bugfix:] Wrong default values for `isEnabled` and `isActive`.
|
||||
|
||||
#### Version 0.6.1 (14.12.2014)
|
||||
- [enhancement:] Set default settings through `setDefaults`.
|
||||
- [enhancement:] New method `isEnabled` to receive if mode is enabled.
|
||||
- [enhancement:] New method `isActive` to receive if mode is active.
|
||||
- [bugfix:] Events caused thread collision.
|
||||
|
||||
#### Further informations
|
||||
- The former `plugin.backgroundMode` namespace has been deprecated and will be removed with the next major release.
|
||||
- See [CHANGELOG.md][changelog] to get the full changelog for the plugin.
|
||||
@ -229,6 +226,15 @@ cordova.plugins.backgroundMode.configure({
|
||||
})
|
||||
```
|
||||
|
||||
#### Run in background without notification
|
||||
In silent mode the plugin will not display a notification - which is not the default. Be aware that Android recommends adding a notification otherwise the OS may pause the app.
|
||||
|
||||
```javascript
|
||||
cordova.plugins.backgroundMode.configure({
|
||||
silent: true
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@ -36,6 +36,7 @@ import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Puts the service in a foreground state, where the system considers it to be
|
||||
@ -84,7 +85,11 @@ public class ForegroundService extends Service {
|
||||
public void keepAwake() {
|
||||
final Handler handler = new Handler();
|
||||
|
||||
if (!this.inSilentMode()) {
|
||||
startForeground(NOTIFICATION_ID, makeNotification());
|
||||
} else {
|
||||
Log.w("BackgroundMode", "In silent mode app may be paused by OS!");
|
||||
}
|
||||
|
||||
BackgroundMode.deleteUpdateSettings();
|
||||
|
||||
@ -160,7 +165,7 @@ public class ForegroundService extends Service {
|
||||
* @return
|
||||
* The resource ID of the app icon
|
||||
*/
|
||||
private int getIconResId () {
|
||||
private int getIconResId() {
|
||||
Context context = getApplicationContext();
|
||||
Resources res = context.getResources();
|
||||
String pkgName = context.getPackageName();
|
||||
@ -170,4 +175,16 @@ public class ForegroundService extends Service {
|
||||
|
||||
return resId;
|
||||
}
|
||||
|
||||
/**
|
||||
* In silent mode no notification has to be added.
|
||||
*
|
||||
* @return
|
||||
* True if silent: was set to true
|
||||
*/
|
||||
private boolean inSilentMode() {
|
||||
JSONObject settings = BackgroundMode.getSettings();
|
||||
|
||||
return settings.optBoolean("silent", false);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ exports._defaults = {
|
||||
title: 'App is running in background',
|
||||
text: 'Doing heavy tasks.',
|
||||
ticker: 'App is running in background',
|
||||
resume: true
|
||||
resume: true,
|
||||
silent: false
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user