android - 如何在 Flutter 中折叠通知?使用本地推送通知插件和 CloudFunctions
问题描述
我正在使用云功能通过设备令牌发送通知。
const payload: admin.messaging.MessagingPayload = {
notification: {
title: `updatedBy: ${updatedBy}`,
body: `nova messagem ${increment}`,
},
}
return fcm.sendToDevice(userToken, payload, options).then((value) => {
console.log(value.results);
}).catch((error) => {
console.log(error);
})
但是,所有通知都被删除了,我非常想管理这些卡在系统托盘中的通知,无论如何我可以使用这些插件来调节具有如此“复杂性”的通知吗?(本地推送通知、FCM、cloudfunctions)不使用本机代码(kotlin、android)?因为我不知道android结构是如何工作的......
我可以使用 cancelAll (本地推送通知)
FlutterLocalNotificationsPlugin.cancelAll()
来自本地推送通知:https ://pub.dev/documentation/flutter_local_notifications/latest/
但是太不灵活了
我也可以使用特定的“ID”使用取消通知,但我不知道如何获取该通知“id”
FlutterLocalNotificationsPlugin.cancel(notificationId)
那么,如何解决这个问题呢?
这样,我可以明智地删除我想要的任何通知,但基本上,我只想折叠相同类型的通知,例如在 Whatsapp 上,当有人向您发送超过 1 条消息时,系统托盘中只有一个通知说“他”发送了不止一条消息(而不是一大堆通知)。
我刚刚看了https://github.com/chetdeva/collapsing-notifications/tree/a5e8867e24f53ff8caca761c7faa13242c607dba
此 github 代码适用于文章https://medium.com/fueled-engineering/collapsing-fcm-notification-like-a-pro-102a4946b350
如果在颤振项目中实施起来不太困难,那将是完美的,我还在stackoverflow中查看了这里的每一篇文章,看到没有人回答过这个问题
[编辑]:我不能使用的原因
FlutterLocalNotificationsPlugin.cancelAll()
这是因为我使用 fcm 方法来监听通知,我试图将该方法放在一些 fcm 监听器中但没有成功。
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
解决方案
推荐阅读
- solr - 根据 Solr 中的搜索查询请求将字段添加到架构
- javascript - Axios:在 POST 请求的正文中发送变量而不是参数
- javascript - 覆盖日期构造函数
- android - android studio 模拟器和真正的 android 设备 Mate 9 选择的不同布局
- javascript - 移动设备 (iOS) 上 iFrame 的大小问题
- spring-boot - 无法使用客户端中的 Spring Cloud Config 将 Hikari 属性外部化
- python - 使用列表推导而不是通常的 for 循环从重复成员中删除列表
- python - 如何不断地添加到一个字符串?
- r - 如何删除R中同一列中匹配的部分字符串?
- java - EJB3 MessageDrivenBean 抛出异常 当使用外部 ActiveMQ 队列时,此类不被信任序列化为 ObjectMessage 有效负载