[英]How to dismiss notification after action button clicked without opening the app?
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.我正在使用awesome_notifications显示通知,并且有关闭通知的操作按钮,但问题是如果应用程序在后台,并且单击操作按钮,那么它会关闭通知但也打开应用程序,而我没有想。 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,
),
]
);
Found the answer while surfing the GitHub Repository of awesome_notifications .在浏览awesome_notifications 的 GitHub 存储库时找到了答案。 The
notification
can straightly be dismissed without opening the app by adding buttonType
as ActionButtonType.DisabledAction
in the NotificationActionButton
通过在
NotificationActionButton
中添加buttonType
作为ActionButtonType.DisabledAction
可以直接关闭notification
而无需打开应用程序
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
.注意:这样做不会触发
actionStream
中的任何receivedAction
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.