Added extra settings for Lollipop devices

Two settings have been added:
- Notification visibility - allows the notification to be made visible on a
secure lock screen
- Color - used to set the color of the notification circle that contains the
icon
This commit is contained in:
Gearóid Moroney 2015-06-03 16:33:09 +01:00
parent f41787afe1
commit cec56db33c
3 changed files with 25 additions and 11 deletions

View File

@ -201,21 +201,18 @@ document.addEventListener('deviceready', function () {
To indicate that the app is executing tasks in background and being paused would disrupt the user, the plug-in has to create a notification while in background - like a download progress bar.
#### Override defaults
The title, ticker and text for that notification can be customized as follows:
The title, ticker, text for that notification can be customized as below. Also, by default the app will come to foreground when tapping on the notification. That can be changed by setting resume to false. On Android 5.0+, the color option will set the background color of the notification circle. Also on Android 5.0+, setting isPublic to true will make the full notification show on a secure lockscreen.
All of these fields are optional - only override the things you need to.
```javascript
cordova.plugins.backgroundMode.setDefaults({
title: String,
ticker: String,
text: String
})
```
By default the app will come to foreground when taping on the notification. That can be changed also.
```javascript
cordova.plugins.backgroundMode.setDefaults({
resume: false
text: String,
resume: true / false,
color: "#123456",
isPublic: true / false
})
```

View File

@ -33,6 +33,7 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@ -141,6 +142,20 @@ public class ForegroundService extends Service {
.setOngoing(true)
.setSmallIcon(getIconResId());
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if(settings.optBoolean("isPublic") == true) {
notification.setVisibility(Notification.VISIBILITY_PUBLIC);
}
if(!settings.optString("color").equals("")) {
try {
notification.setColor(Color.parseColor(settings.optString("color")));
} catch (Exception e) {
Log.e("BackgroundMode", settings.optString("color") + " is not a valid color");
}
}
}
if (intent != null && settings.optBoolean("resume")) {
PendingIntent contentIntent = PendingIntent.getActivity(

View File

@ -65,7 +65,9 @@ exports._defaults = {
text: 'Doing heavy tasks.',
ticker: 'App is running in background',
resume: true,
silent: false
silent: false,
isPublic: false,
color: ""
};