我有一个可以发出警报的应用程序(带有自定义声音的通知)。但是通知栏里有很多通知后,通知声音就不起作用了。所以我想从通知栏清除 1 小时前的通知。类似这样的事情...
我知道如何删除通知栏中的所有通知,但我只想删除 FLUTTER 中的旧通知。 注意:运行该应用程序的设备具有 android 8+
知道如何实现这一目标吗?
如果您使用 flutter_local_notification 包,您可以通过其 id 删除特定通知。
如果您尝试删除 firebase 库本身呈现的远程通知,那么我认为没有办法检测和删除特定通知。
使用 lib flutter_local_notifications。简单,您可以使用以下代码删除应用程序的所有通知:
logoutFirebase(){
// messaging.unsubscribeFromTopic("all");
FirebaseMessaging.instance.deleteToken();
// call to API delete columns ft_token with id and device if need
// this line to remove all notification
localNotification.cancelAll();
}
如果您正在使用很棒的通知,您可以做的就是跟踪通知及其 ID。
AwesomeNotifications().createNotification(
content: NotificationContent(
// the id is used to identify each notification. So if you have a static id like 123, when a new notification comes in, the old one goes out.
id: <your-id>,
title: title,
body: body,
category: NotificationCategory.Alarm,
locked: false,
),
)
因此,要覆盖通知或清除通知,您只需创建另一个具有相同 ID 的通知即可。