Skip to content

Commit 088715d

Browse files
committed
fix(local-notifications): honor autoCancel when a notification is tapped
handleNotificationActionPerformed dismissed the tapped notification unconditionally, so `autoCancel: false` had no effect on tap even though the builder sets setAutoCancel() from it. Read autoCancel from the notification payload carried in the intent (default true) and skip the explicit dismissal when the caller opted out. Fixes the behavior reported in #1384.
1 parent 0bfde98 commit 088715d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ public JSObject handleNotificationActionPerformed(Intent data, NotificationStora
8383
}
8484
String menuAction = data.getStringExtra(LocalNotificationManager.ACTION_INTENT_KEY);
8585

86-
dismissVisibleNotification(notificationId);
87-
8886
dataJson.put("actionId", menuAction);
8987
JSONObject request = null;
9088
try {
@@ -93,6 +91,15 @@ public JSObject handleNotificationActionPerformed(Intent data, NotificationStora
9391
request = new JSObject(notificationJsonString);
9492
}
9593
} catch (JSONException e) {}
94+
95+
// Only dismiss the tapped notification when autoCancel allows it; the
96+
// builder already applies setAutoCancel(), but this explicit cancel used
97+
// to run unconditionally, making `autoCancel: false` a no-op on tap.
98+
boolean autoCancel = request == null || request.optBoolean("autoCancel", true);
99+
if (autoCancel) {
100+
dismissVisibleNotification(notificationId);
101+
}
102+
96103
dataJson.put("notification", request);
97104
return dataJson;
98105
}

0 commit comments

Comments
 (0)