parent
0b9854e1bc
commit
270abbff02
@ -1,4 +1,7 @@
|
|||||||
## ChangeLog
|
## ChangeLog
|
||||||
|
#### Version 0.6.3 (not yet released)
|
||||||
|
- [feature:] Silent mode for Android
|
||||||
|
|
||||||
#### Version 0.6.2 (14.12.2014)
|
#### Version 0.6.2 (14.12.2014)
|
||||||
- [bugfix:] Type error
|
- [bugfix:] Type error
|
||||||
- [bugfix:] Wrong default values for `isEnabled` and `isActive`.
|
- [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
|
## ChangeLog
|
||||||
|
#### Version 0.6.3 (not yet released)
|
||||||
|
- [feature:] Silent mode for Android
|
||||||
|
|
||||||
#### Version 0.6.2 (14.12.2014)
|
#### Version 0.6.2 (14.12.2014)
|
||||||
- [bugfix:] Type error
|
- [bugfix:] Type error
|
||||||
- [bugfix:] Wrong default values for `isEnabled` and `isActive`.
|
- [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
|
#### Further informations
|
||||||
- The former `plugin.backgroundMode` namespace has been deprecated and will be removed with the next major release.
|
- 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.
|
- 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
|
## Contributing
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import android.content.res.Resources;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts the service in a foreground state, where the system considers it to be
|
* 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() {
|
public void keepAwake() {
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
|
|
||||||
startForeground(NOTIFICATION_ID, makeNotification());
|
if (!this.inSilentMode()) {
|
||||||
|
startForeground(NOTIFICATION_ID, makeNotification());
|
||||||
|
} else {
|
||||||
|
Log.w("BackgroundMode", "In silent mode app may be paused by OS!");
|
||||||
|
}
|
||||||
|
|
||||||
BackgroundMode.deleteUpdateSettings();
|
BackgroundMode.deleteUpdateSettings();
|
||||||
|
|
||||||
@ -160,7 +165,7 @@ public class ForegroundService extends Service {
|
|||||||
* @return
|
* @return
|
||||||
* The resource ID of the app icon
|
* The resource ID of the app icon
|
||||||
*/
|
*/
|
||||||
private int getIconResId () {
|
private int getIconResId() {
|
||||||
Context context = getApplicationContext();
|
Context context = getApplicationContext();
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
String pkgName = context.getPackageName();
|
String pkgName = context.getPackageName();
|
||||||
@ -170,4 +175,16 @@ public class ForegroundService extends Service {
|
|||||||
|
|
||||||
return resId;
|
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',
|
title: 'App is running in background',
|
||||||
text: 'Doing heavy tasks.',
|
text: 'Doing heavy tasks.',
|
||||||
ticker: 'App is running in background',
|
ticker: 'App is running in background',
|
||||||
resume: true
|
resume: true,
|
||||||
|
silent: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user