How to dismiss notification after action button clicked without opening the app?

115

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.

Share:
115
Siddharth Mehra
Author by

Siddharth Mehra

I know nothing but want to know everything!!!

Updated on January 03, 2023

Comments

  • Siddharth Mehra
    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: enter image description here

    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
      Yashraj over 2 years
      Add code that notification action buttons.
    • Siddharth Mehra
      Siddharth Mehra over 2 years
      Code Added, please check!
    • Yashraj
      Yashraj over 2 years
    • Maurice Lam
      Maurice Lam over 2 years
      Their 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
      Siddharth Mehra over 2 years
      Okay, I found the answer, thanks for your help!