flutter_local_notifications
flutter_local_notifications copied to clipboard
cancelNotification in AndroidNotificationAction it's not working
Describe the bug I modified the example file in particular in the text response action "_showNotificationWithTextAction" by adding "cancelNotification: false" in order that the notification remains even following the response. The effect is that upon clicking on sending the test message a perpetual loader.
https://github.com/user-attachments/assets/a31ddba7-b749-43e8-9619-c1df8eb319c6
To Reproduce Change the method _showNotificationWithTextAction in the example code like this
Future<void> _showNotificationWithTextAction() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'your channel id',
'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker',
actions: <AndroidNotificationAction>[
AndroidNotificationAction(
'text_id_1',
'Enter Text',
icon: DrawableResourceAndroidBitmap('food'),
cancelNotification: false,
inputs: <AndroidNotificationActionInput>[
AndroidNotificationActionInput(
label: 'Enter a message',
),
],
),
],
);
Launch the example app --> click on the "Show notification with text action" button --> respond to the notification and send
Expected behavior The expected behavior is that the message is sent and the notification remains present
In manifest, you may have forgot to add this -
<receiver
android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver"
android:exported="false"/>
From https://github.com/MaikuB/flutter_local_notifications/issues/2152
My manifest is correct, but the manifest in the example is also correct and in fact the behavior is the same. (https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/AndroidManifest.xml)
I tried to reproduce this onn the Android emulator. Yet to try on my Pixel device as I won't get to do so until later but expect to run into same behaviour.
Scenario 1: when cancelNotification is left to the default of true. The notification remains on screen and shows what was entered. I'm not sure if you saw the same behaviour but if you did, it seems to align with what you actually want. There may be a gap in documentation on this specific combination
https://github.com/user-attachments/assets/80180cc1-b44f-4abd-8046-981d8d908222
Scenario 2: when I set it to cancelNotification to false as mentioned in the original post, the loader showed up but then disappeared. Based on this, it looks like a device-specific issue and if so, not much else the plugin can do
https://github.com/user-attachments/assets/8e88f575-ac4f-4ad9-889e-9a57359b5f72
When given cancelNotification: false, the loader sometimes doesn't disappear. I was able to reproduce this 4/10 times. I tried this in two different devices and the outcome was same. I tried the example code also. It also had the same issue.
An interesting thing is that the background call (Send reply in my case) is executed and completed successfully.