gpt4 book ai didi

android - Firebase Cloud Messaging 不发送数据负载

转载 作者:行者123 更新时间:2023-11-29 01:08:24 25 4
gpt4 key购买 nike

来自 Defining message payload 处的 Firebase 云消息传递文档:

You can specify one or both message types by creating an object with the data and / or notification keys.

文档给出了组合消息的示例:

var payload = {
notification: {
title: "$GOOG up 1.43% on the day",
body: "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day."
},
data: {
stock: "GOOG",
open: 829.62,
close: "635.67"
}
};

也来自 Handle notification messages in a backgrounded app 的文档:

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

我正在发送带有此负载的通知:

const payload = {
notification: {
title: '...',
body: '...',
},
data: {
test: "test"
},
};
admin.messaging().sendToDevice(tokens, payload).then(...)

但是 extras 总是空的:

Intent intent = getIntent();
if (intent != null) {
Bundle extras = intent.getExtras();
if (extras != null) {
// do something
}
}

我做错了什么?

最佳答案

应用在接收包含通知和数据负载的消息时的行为取决于应用是在后台还是在前台——本质上,它在接收时是否处于 Activity 状态。

  • 在后台时,应用会在通知托盘中接收通知负载,并且仅在用户点击通知时处理数据负载。

  • 在前台时,您的应用会收到一个包含两个可用负载的消息对象。

所以,基本上如果应用程序在前台,则 intent 不会有任何额外的通知。如果不是这种情况,则表示您在配置中做错了什么。

关于android - Firebase Cloud Messaging 不发送数据负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45316667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com