Browse Source

Fix playing sound again when calling update method

Sebastián Katzer 8 năm trước cách đây
mục cha
commit
38503d9c91
1 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 14 1
      src/android/notification/Builder.java

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

@@ -39,6 +39,7 @@ import de.appplant.cordova.plugin.notification.action.Action;
 
 import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
 import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
+import static de.appplant.cordova.plugin.notification.Notification.EXTRA_UPDATE;
 
 /**
  * Builder class for local notifications. Build fully configured local
@@ -134,7 +135,6 @@ public final class Builder {
                 .setAutoCancel(options.isAutoClear())
                 .setOngoing(options.isSticky())
                 .setColor(options.getColor())
-                .setSound(sound)
                 .setVisibility(options.getVisibility())
                 .setPriority(options.getPriority())
                 .setShowWhen(options.getShowWhen())
@@ -143,6 +143,10 @@ public final class Builder {
                 .setGroupSummary(options.getGroupSummary())
                 .setLights(options.getLedColor(), options.getLedOn(), options.getLedOff());
 
+        if (sound != Uri.EMPTY && !isUpdate()) {
+            builder.setSound(sound);
+        }
+
         if (options.isWithProgressBar()) {
             builder.setProgress(
                     options.getProgressMaxValue(),
@@ -393,4 +397,13 @@ public final class Builder {
                 context, reqCode, intent, FLAG_CANCEL_CURRENT);
     }
 
+    /**
+     * If the builder shall build an notification or an updated version.
+     *
+     * @return true in case of an updated version.
+     */
+    private boolean isUpdate() {
+        return extras != null && extras.getBoolean(EXTRA_UPDATE, false);
+    }
+
 }