diff --git a/README.md b/README.md index acb5f77..7b4d7f0 100644 --- a/README.md +++ b/README.md @@ -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 }) ``` diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java index a19283c..1490e4b 100644 --- a/src/android/ForegroundService.java +++ b/src/android/ForegroundService.java @@ -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( diff --git a/www/background-mode.js b/www/background-mode.js index d4a2836..5ffb3d4 100644 --- a/www/background-mode.js +++ b/www/background-mode.js @@ -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: "" };