当后台 firebase 通知中的应用程序有带有有效负载的通知时,是否调用远程消息方法
When app in background firebase notification have notification with payload then remote message method call or not
我会尝试像这样的格式在后台获取数据
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
因此数据是否通过 onMessageReceived(RemoteMessage message) 方法传递,我不知道有人可以帮助我解决这个问题。
要让您的应用在后台时可点击通知,您需要在通知负载中添加 click_action
属性。
请查看 Firebase 文档的 section。
此外,当您定义 click_action
属性时,您还需要在要启动的 activity 的 <intent-filter>
中有一个相应的 <action>
属性。
这个 video 解释得相当详细。
不过请注意,如果您从 Firebase 控制台发送通知,则无法设置 click__action
属性。只有从您自己的管理服务器或使用 Firebase Cloud Functions 发送通知时,您才能这样做。
最后,在启动的 activity 中,您可以使用数据属性设置额外的 Data
(也显示在我上面链接的同一文档中)。当您通过单击通知启动您的应用程序时,您可以使用 getIntent()
获取通知数据。查看 以了解有关如何执行此操作的更多详细信息。
例如,如果您的通知负载具有以下结构,
payload = {
notification: {
title: `You ordered a new product`,
click_action : 'HANDLE_NOTIFICATION',
},
data : {
product_id : 'ABC98292',
type : `Clothes`,
product_name : 'Cotton spring shirt'
}
};
然后,将过滤器放在点击通知时要打开的 activity 的标签中。一个例子如下:-
<intent-filter>
<action android:name="HANDLE_NOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
然后您可以使用 getIntent().getStringsExtra("product_id")
等从通知中获取 product_id。
这样,您将打开所需的 activity,并可以使用从您的通知中获得的相关详细信息填充它。
我会尝试像这样的格式在后台获取数据
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
因此数据是否通过 onMessageReceived(RemoteMessage message) 方法传递,我不知道有人可以帮助我解决这个问题。
要让您的应用在后台时可点击通知,您需要在通知负载中添加 click_action
属性。
请查看 Firebase 文档的 section。
此外,当您定义 click_action
属性时,您还需要在要启动的 activity 的 <intent-filter>
中有一个相应的 <action>
属性。
这个 video 解释得相当详细。
不过请注意,如果您从 Firebase 控制台发送通知,则无法设置 click__action
属性。只有从您自己的管理服务器或使用 Firebase Cloud Functions 发送通知时,您才能这样做。
最后,在启动的 activity 中,您可以使用数据属性设置额外的 Data
(也显示在我上面链接的同一文档中)。当您通过单击通知启动您的应用程序时,您可以使用 getIntent()
获取通知数据。查看
例如,如果您的通知负载具有以下结构,
payload = {
notification: {
title: `You ordered a new product`,
click_action : 'HANDLE_NOTIFICATION',
},
data : {
product_id : 'ABC98292',
type : `Clothes`,
product_name : 'Cotton spring shirt'
}
};
然后,将过滤器放在点击通知时要打开的 activity 的标签中。一个例子如下:-
<intent-filter>
<action android:name="HANDLE_NOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
然后您可以使用 getIntent().getStringsExtra("product_id")
等从通知中获取 product_id。
这样,您将打开所需的 activity,并可以使用从您的通知中获得的相关详细信息填充它。