【问题标题】:How to dismiss notification after action button clicked without opening the app?单击操作按钮后如何在不打开应用程序的情况下关闭通知?
【发布时间】:2022-01-13 06:02:12
【问题描述】:

我正在使用awesome_notifications 显示通知,并且有关闭通知的操作按钮,但问题是如果应用程序在后台,并且单击操作按钮,那么它会关闭通知但也打开应用程序我不想要。那么如何在不打开应用程序的情况下单击操作按钮时关闭通知?该通知还包含另一个打开应用程序的操作按钮,但第二个不应该。 这种情况我该怎么办?

这是目前发生的情况:

显示通知的代码:

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,
           ),
         ]
     );

【问题讨论】:

  • 添加通知操作按钮的代码。
  • 代码已添加,请查看!
  • 他们的网站 (pub.dev/packages/awesome_notifications) 在“后续步骤”部分显示 Add an option to choose if a notification action should bring the app to foreground or not.,所以我认为该软件包尚不支持。
  • 好的,我找到了答案,感谢您的帮助!

标签: android flutter push-notification notifications dismiss


【解决方案1】:

在浏览awesome_notificationsGitHub Repository 时找到了答案。 通过在NotificationActionButton 中添加buttonType 作为ActionButtonType.DisabledAction 可以直接关闭notification 而不打开应用程序

就像这样:

NotificationActionButton(
   key: 'DISMISS',
   label: 'Dismiss',
   autoDismissible: true,
   buttonType: ActionButtonType.DisabledAction,
   isDangerousOption: true
)

注意:这样做不会触发actionStream中的任何receivedAction

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多