Ver Fonte

Made small icon on Android optional

Sebastián Katzer há 10 anos atrás
pai
commit
4f9f3d0697

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo
 
 #### Version 0.8.3 (not yet released)
 - New "quarter" intervall for iOS & Android
+- Made small icon optional (Android)
 - Fixed #588 crash when basename & extension can't be extracted (Android)
 - Fixed #732 loop between update and trigger (Android)
 - Fixed #710 crash due to >500 notifications (Android)

+ 9 - 3
src/android/notification/Builder.java

@@ -115,7 +115,8 @@ public class Builder {
      * Creates the notification with all its options passed through JS.
      */
     public Notification build() {
-        Uri sound = options.getSoundUri();
+        Uri sound     = options.getSoundUri();
+        int smallIcon = options.getSmallIcon();
         NotificationCompat.Builder builder;
 
         builder = new NotificationCompat.Builder(context)
@@ -124,8 +125,6 @@ public class Builder {
                 .setContentText(options.getText())
                 .setNumber(options.getBadgeNumber())
                 .setTicker(options.getText())
-                .setSmallIcon(options.getSmallIcon())
-                .setLargeIcon(options.getIconBitmap())
                 .setAutoCancel(options.isAutoClear())
                 .setOngoing(options.isOngoing())
                 .setLights(options.getLedColor(), 500, 500);
@@ -134,6 +133,13 @@ public class Builder {
             builder.setSound(sound);
         }
 
+        if (smallIcon == 0) {
+            builder.setSmallIcon(options.getIcon());
+        } else {
+            builder.setSmallIcon(options.getSmallIcon());
+            builder.setLargeIcon(options.getIconBitmap());
+        }
+
         applyDeleteReceiver(builder);
         applyContentReceiver(builder);
 

+ 18 - 5
src/android/notification/Options.java

@@ -131,7 +131,7 @@ public class Options {
         if (options.has("iconUri"))
             return;
 
-        Uri iconUri = assets.parse(options.optString("icon", "icon"));
+        Uri iconUri  = assets.parse(options.optString("icon", "icon"));
         Uri soundUri = assets.parseSound(options.optString("sound", null));
 
         try {
@@ -282,20 +282,33 @@ public class Options {
     }
 
     /**
-     * Small icon resource ID for the local notification.
+     * Icon resource ID for the local notification.
      */
-    public int getSmallIcon () {
-        String icon = options.optString("smallIcon", "");
+    public int getIcon () {
+        String icon = options.optString("icon", "");
 
         int resId = assets.getResIdForDrawable(icon);
 
         if (resId == 0) {
-            resId = android.R.drawable.screen_background_dark;
+            resId = getSmallIcon();
+        }
+
+        if (resId == 0) {
+            resId = android.R.drawable.ic_popup_reminder;
         }
 
         return resId;
     }
 
+    /**
+     * Small icon resource ID for the local notification.
+     */
+    public int getSmallIcon () {
+        String icon = options.optString("smallIcon", "");
+
+        return assets.getResIdForDrawable(icon);
+    }
+
     /**
      * JSON object as string.
      */

+ 2 - 2
www/local-notification-util.js

@@ -60,8 +60,8 @@ exports.applyPlatformSpecificOptions = function () {
 
     switch (device.platform) {
     case 'Android':
-        defaults.icon      = 'res://icon';
-        defaults.smallIcon = 'res://ic_popup_reminder';
+        defaults.icon      = 'res://ic_popup_reminder';
+        defaults.smallIcon = undefined;
         defaults.ongoing   = false;
         defaults.autoClear = true;
         defaults.led       = 'FFFFFF';