소스 검색

Support for silent, group, groupSummary flags on Android

Sebastián Katzer 8 년 전
부모
커밋
52623f11f6
4개의 변경된 파일45개의 추가작업 그리고 15개의 파일을 삭제
  1. 1 1
      src/android/LocalNotification.java
  2. 8 1
      src/android/notification/Builder.java
  3. 21 1
      src/android/notification/Options.java
  4. 15 12
      www/local-notification-util.js

+ 1 - 1
src/android/LocalNotification.java

@@ -638,7 +638,7 @@ public class LocalNotification extends CordovaPlugin {
      *
      * @return "background" or "foreground"
      */
-    static String getApplicationState () {
+    static String getApplicationState() {
         return isInBackground ? "background" : "foreground";
     }
 

+ 8 - 1
src/android/notification/Builder.java

@@ -90,10 +90,15 @@ public class Builder {
         int smallIcon = options.getSmallIcon();
         NotificationCompat.Builder builder;
 
-        builder = new NotificationCompat.Builder(context, "group")
+        if (options.isSilent()) {
+            return new Notification(context, options);
+        }
+
+        builder = new NotificationCompat.Builder(context, "channel")
                 .setDefaults(options.getDefaults())
                 .setContentTitle(options.getTitle())
                 .setContentText(options.getText())
+                .setTicker(options.getText())
                 .setNumber(options.getBadgeNumber())
                 .setAutoCancel(options.isAutoClear())
                 .setOngoing(options.isSticky())
@@ -103,6 +108,8 @@ public class Builder {
                 .setPriority(options.getPriority())
                 .setShowWhen(options.getShowWhen())
                 .setUsesChronometer(options.isWithProgressBar())
+                .setGroup(options.getGroup())
+                .setGroupSummary(options.getGroupSummary())
                 .setLights(options.getLedColor(), options.getLedOn(), options.getLedOff());
 
         if (options.isWithProgressBar()) {

+ 21 - 1
src/android/notification/Options.java

@@ -30,7 +30,6 @@ import org.json.JSONArray;
 import org.json.JSONObject;
 
 import java.io.IOException;
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -487,6 +486,27 @@ public class Options {
         return pics;
     }
 
+    /**
+     * The group for that notification.
+     */
+    String getGroup() {
+        return options.optString("group", null);
+    }
+
+    /**
+     * If the group shall show a summary.
+     */
+    boolean getGroupSummary() {
+        return options.optBoolean("groupSummary", false);
+    }
+
+    /**
+     * Gets the value of the silent flag.
+     */
+    boolean isSilent() {
+        return options.optBoolean("silent", false);
+    }
+
     /**
      * Gets the raw trigger spec as provided by the user.
      */

+ 15 - 12
www/local-notification-util.js

@@ -31,6 +31,7 @@ exports._defaults = {
     badge:   undefined,
     data:    undefined,
     icon:    undefined,
+    silent:  false,
     trigger: { type: 'calendar' },
     actions: [],
     actionGroupId: undefined,
@@ -51,18 +52,20 @@ exports.applyPlatformSpecificOptions = function () {
 
     switch (device.platform) {
     case 'Android':
-        defaults.summary    = undefined;
-        defaults.icon       = 'res://icon';
-        defaults.smallIcon  = undefined;
-        defaults.sticky     = false;
-        defaults.autoClear  = true;
-        defaults.led        = true;
-        defaults.color      = undefined;
-        defaults.vibrate    = false;
-        defaults.lockscreen = true;
-        defaults.showWhen   = true;
-        defaults.defaults   = 0;
-        defaults.priority   = 0;
+        defaults.group        = undefined;
+        defaults.groupSummary = false;
+        defaults.summary      = undefined;
+        defaults.icon         = 'res://icon';
+        defaults.smallIcon    = undefined;
+        defaults.sticky       = false;
+        defaults.autoClear    = true;
+        defaults.led          = true;
+        defaults.color        = undefined;
+        defaults.vibrate      = false;
+        defaults.lockscreen   = true;
+        defaults.showWhen     = true;
+        defaults.defaults     = 0;
+        defaults.priority     = 0;
         break;
     }
 };