From cd1fb46dcc810b52c3d8604b715c6f6fbc079780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gear=C3=B3id=20Moroney?= Date: Thu, 4 Jun 2015 10:59:11 +0100 Subject: [PATCH] Added customisable notification icon for Android --- README.md | 5 +++-- src/android/ForegroundService.java | 4 ++-- www/background-mode.js | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b4d7f0..0bc6a4a 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ 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, 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. +The title, ticker, text and icon 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. @@ -210,9 +210,10 @@ cordova.plugins.backgroundMode.setDefaults({ title: String, ticker: String, text: String, + icon: "icon" // this will look for icon.png in platforms/android/res/drawable resume: true / false, color: "#123456", - isPublic: true / false + isPublic: true / false, }) ``` diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java index 9a9b90a..21c98e0 100644 --- a/src/android/ForegroundService.java +++ b/src/android/ForegroundService.java @@ -205,12 +205,12 @@ public class ForegroundService extends Service { * The resource ID of the app icon */ private int getIconResId() { + JSONObject settings = BackgroundMode.getSettings(); Context context = getApplicationContext(); Resources res = context.getResources(); String pkgName = context.getPackageName(); - int resId; - resId = res.getIdentifier("icon", "drawable", pkgName); + int resId = res.getIdentifier(settings.optString("icon", "icon"), "drawable", pkgName); return resId; } diff --git a/www/background-mode.js b/www/background-mode.js index 5ffb3d4..4cb7081 100644 --- a/www/background-mode.js +++ b/www/background-mode.js @@ -67,7 +67,8 @@ exports._defaults = { resume: true, silent: false, isPublic: false, - color: "" + color: "", + icon: "icon" };