android - 在飞行模式下发送多个远程推送通知,当重新连接时只收到最后一个

标签 android firebase push-notification firebase-cloud-messaging

我正在尝试使用 FCM 在我的 Android 应用程序上实现远程推送通知,它在有互联网连接时完美运行。但是当将设备置于飞行模式,然后发送多个远程推送通知,然后重新连接时,我只收到最新的一个。

我已经尝试更改有效负载中的 TTL,使用不同的折叠键和更改优先级。没有任何效果。这是我的通知负载示例:

{"GCM": "{ \"notification\": { \"text\": \"test\",  \"title\": \"Titre\" },\"data\": { \"time_to_live\": 3600,\"collapse_key\":\"deals\"}, \"priority\": \"high\" }"}

仅供引用:通知本身是从 AWS SNS 发送到 FCM。

有谁知道为什么我们只收到最新的,以及如何才能收到所有的东西?

最佳答案

你不应该使用 collapse_key。正如 documentation 中所述:

A non-collapsible message denotes that each individual message is delivered to the device. A non-collapsible message delivers some useful content, as opposed to a collapsible message like a content-free "ping" to the mobile app to contact the server to fetch data.

...

A collapsible message is a message that may be replaced by a new message if it has yet to be delivered to the device.

To mark a message as collapsible on Android, include the collapse_key parameter in the message payload. FCM allows a maximum of four different collapse keys per Android device to be used by the app server at any given time. In other words, the FCM server can simultaneously store four different collapsible messages per device, each with a different collapse key. If you exceed this number, FCM only keeps four collapse keys, with no guarantees about which ones are kept.

换句话说:如果 collapse_key 相同,FCM 将用新的推送通知请求内容替换最新未收到的推送通知内容。

还有一点截图,因为粘贴表格不方便:

Should you use collapsible messages or not? A table with explanations is shown for you to decide.

关于android - 在飞行模式下发送多个远程推送通知,当重新连接时只收到最后一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62470932/

相关文章:

android - Android 上带有 GoogleAccountCredential.newChooseAccountIntent() 的 java.lang.NoClassDefFoundError

ios - 希望仅允许单域 (@example.com) 电子邮件在 firebase 中进行注册,但无法正常工作

node.js - 未经用户同意向 Web 应用程序发送推送通知

angular - 电容器 3 且没有导出成员 PushNotification

android - 如何检测在 Android 中单击了通知包/组?

android - fragment 最佳实践 - Android

安卓工作室 : CardView change function once clicked

java - 在运行时选择 Firebase 数据库

android - 如何解决 Google API 建议、程序类型已存在的问题?

ios - 代码正在跳过 firebase 快照