How to dismiss notification after action button clicked without opening the app?
Found the answer while surfing the GitHub Repository of awesome_notifications.
The notification
can straightly be dismissed without opening the app by adding buttonType
as ActionButtonType.DisabledAction
in the NotificationActionButton
just like this:
NotificationActionButton(
key: 'DISMISS',
label: 'Dismiss',
autoDismissible: true,
buttonType: ActionButtonType.DisabledAction,
isDangerousOption: true
)
Note: Doing so will not trigger any receivedAction
in the actionStream
.
Comments
-
Siddharth Mehra over 1 year
I am showing a notification using awesome_notifications and there is action buttons that dismiss the notification, but the problem is if the app is in the background, and the action button clicked, then it dismisses the notification but open the app too which I don't want. So how can I just dismiss the notification when the action button is clicked without opening the app? The notification also contains another action button that opens the app but the second should not. What should I do in that case?
This is what currently happens:
Code to show notification:
AwesomeNotifications().createNotification( content: NotificationContent( id: 333, title: 'Incoming Call', body: 'from $callerName', category: NotificationCategory.Call, channelKey: 'call_channel', largeIcon: 'asset://assets/images/logo_square.png', wakeUpScreen: true, fullScreenIntent: true, autoDismissible: false, showWhen: true, displayOnBackground: true, displayOnForeground: true, payload: { "callerName": callerName, "callerUsername": callerUsername, "callerID": callerID, "callerToken": callerToken, "callerImage": callerImage, }, ), actionButtons: [ NotificationActionButton( key: 'ACCEPT', label: 'Accept Call', color: Colors.green, autoDismissible: true, ), NotificationActionButton( key: 'REJECT', label: 'Reject Call', isDangerousOption: true, autoDismissible: true, ), ] );
-
Yashraj over 2 yearsAdd code that notification action buttons.
-
Siddharth Mehra over 2 yearsCode Added, please check!
-
Yashraj over 2 yearsCheck this :stackoverflow.com/questions/64809766/…
-
Maurice Lam over 2 yearsTheir site (pub.dev/packages/awesome_notifications) says
Add an option to choose if a notification action should bring the app to foreground or not.
in the "Next Steps" section, so I think that is not supported by that package yet. -
Siddharth Mehra over 2 yearsOkay, I found the answer, thanks for your help!
-