From b9381576e004cc8439d9a14d53a60c9f04949a72 Mon Sep 17 00:00:00 2001 From: Sergey Golovin <109870294+begezavr2@users.noreply.github.com> Date: Mon, 20 Jul 2026 19:47:36 +0300 Subject: [PATCH] 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. --- .../localnotifications/LocalNotificationManager.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java index 0b826a546..874a5fae6 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java @@ -83,8 +83,6 @@ public JSObject handleNotificationActionPerformed(Intent data, NotificationStora } String menuAction = data.getStringExtra(LocalNotificationManager.ACTION_INTENT_KEY); - dismissVisibleNotification(notificationId); - dataJson.put("actionId", menuAction); JSONObject request = null; try { @@ -93,6 +91,15 @@ public JSObject handleNotificationActionPerformed(Intent data, NotificationStora request = new JSObject(notificationJsonString); } } catch (JSONException e) {} + + // Only dismiss the tapped notification when autoCancel allows it; the + // builder already applies setAutoCancel(), but this explicit cancel used + // to run unconditionally, making `autoCancel: false` a no-op on tap. + boolean autoCancel = request == null || request.optBoolean("autoCancel", true); + if (autoCancel) { + dismissVisibleNotification(notificationId); + } + dataJson.put("notification", request); return dataJson; }