android - android : what is different between notification and data payload 的通知

标签 android firebase xamarin firebase-cloud-messaging

它看起来与我使用通知或数据的有效负载相同

{"notification":{"body":"Notification Hub test notification"}}

我认为通知负载仍然可以接收通知,即使它关闭而不是后台或前台。我试过了,但似乎在应用程序处于非 Activity 状态时接收不到负载。

看来我收到的数据和通知都是一样的结果

最佳答案

Firebase Cloud Messaging 支持两种类型的消息,通知消息和数据消息。它们之间的区别在于,对于数据消息,您可以在消息中发送自己的数据元素,而对于通知消息,您必须使用预定义的元素。

顾名思义,通知消息类型用于发送通知,这些通知将在通知栏中显示为通知。 FCM 自动处理通知消息,您的应用程序也可以对其进行处理和自定义。数据消息类型用于向客户端发送数据。您的应用程序必须对其进行处理并采取进一步措施。可以发送给客户端的消息大小限制为 4kb。

JSON 格式的通知消息

{"message":{"topic":"deals","notification":{"body":"View latest deals from top brands.","title":"Latest Deals"}}}

JSON格式的数据消息

{"message":{"topic":"deals","data":{"storeNAME":"Nordstorm","deal":"Get upto 50% off on Shoes","dealDesc":"Get upto 50% off on branded shoes.","expiry":"20180110","code":"NORDSH"}}}

JSON格式的通知和数据消息

{"message":{"topic":"deals","data":{"storeNAME":"Nordstorm","deal":"Get upto 50% off on Shoes","dealDesc":"Get upto 50% off on branded shoes.","expiry":"20180110","code":"NORDSH"},"notification":{"body":"View latest deals from top brands.","title":"Latest Deals"}}}

请注意,在数据消息中,数据元素下只允许名称和值对,这意味着数据元素不能具有层次数据或 JSON 数组。

关于android - android : what is different between notification and data payload 的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737110/

相关文章:

java - 如何在 Java 中读取 JSON 文件

Android 谷歌地图准确性问题

c# - 将 PopoverviewController 添加到 UIBarButtonItem Xamarin IOS

android - Android中位置服务和Activity之间的通信?

android - Sherlock Action 条颜色变化

android - 无法解析 : com. google.firebase :firebase-messaging:16. 0.5

java - Redis 客户端阻止 Java 中的 firebase 监听器

java - Firestore,交易已经完成

c# - 在选项卡导航中打开新页面

c# - 我可以从 OnOptionsItemSelected 调用异步方法吗?