ionic-team / ionic-team/capacitor-local-notifications
bug: local-notifications (Android): autoCancel: false is ignored when the notification is tapped
- Dominant language
- Kotlin
- Stars
- 0
- Forks
- 0
- Avg merge
- 11h 50m
- Merged PRs (30d)
- 2
Description
## Bug Report
### Plugin(s)
- `@capacitor/local-notifications` 8.2.1 (bug present on `main` as well)
### Capacitor Version
```
Latest Dependencies:
@capacitor/cli: 8.4.2
@capacitor/core: 8.4.2
@capacitor/android: 8.4.2
Installed Dependencies:
@capacitor/cli: 8.4.2
@capacitor/core: 8.4.2
@capacitor/android: 8.4.2
```
### Platform(s)
- Android
### Current Behavior
Tapping a notification always removes it from the shade, even when it was scheduled with `autoCancel: false`.
The builder does apply the flag (`LocalNotificationManager.buildNotification` → `.setAutoCancel(localNotification.isAutoCancel())`), but `handleNotificationActionPerformed` then calls `dismissVisibleNotification(notificationId)` unconditionally:
https://github.com/ionic-team/capacitor-plugins/blob/main/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L86
That explicit `NotificationManager.cancel()` runs on every tap, so the `autoCancel` value never matters on the tap path.
### Expected Behavior
With `autoCancel: false`, tapping the notification opens the app and the notification stays in the shade (standard Android `setAutoCancel(false)` semantics). This matters for "live status" notifications, e.g. a running-stopwatch readout that should persist until the user stops the timer in the app.
### Code Reproduction
```ts
import { LocalNotifications } from '@capacitor/local-notifications';
await LocalNotifications.requestPermissions();
await LocalNotifications.schedule({
notifications: [
{
id: 1,
title: 'Timer',
body: 'Running',
autoCancel: false,
},
],
});
// Tap the delivered notification → it is removed from the shade,
// although autoCancel is false.
```
### Other Technical Details
Previously reported in ionic-team/capacitor-plugins#1384 (Capacitor 4), which was closed by the bot for lack of a code reproduction and locked; the code path is unchanged.
### Additional Context
Fix PR: https://github.com/ionic-team/capacitor-plugins/pull/2568 — reads `autoCancel` from the notification payload already carried in the tap intent (`NOTIFICATION_OBJ_INTENT_KEY`, default `true`, so existing behavior is preserved for everyone who didn't opt out) and skips the explicit dismissal when the caller set `autoCancel: false`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java, especially handleNotificationActionPerformed and the dismissVisibleNotification call identified in the report. Inspect the notification payload carried in the tap intent and compare the existing behavior with pull request #2568. Done means taps respect autoCancel while preserving current behavior for notifications that do not set it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 20/100