当用户在 Android 中点击一个 Firebase Notification 时,你可以得到以下键值
google.sent_time
(长)来自
(字符串)google.message_id
(字符串)collapse_key
(字符串)
使用以下代码:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
但是,我需要从消息中获取 Body
。可能吗?
最佳答案
如果应用程序在后台,则不是,通知负载中定义的值实际上是为了生成通知。如果您想要访问在消息的通知负载中定义的值,那么您应该在数据负载中重复它们,这样当用户点击通知时,您将能够从 Intent 的额外内容中检索它们。像这样的东西:
{
"to": "/topics/sometopic",
"notification": {
"title": "some title",
"body": "some body"
},
"data": {
"noti_title": "some title",
"noti_body": "some body",
"other_key": "other value"
}
}
关于android - 用户单击时如何获取 Firebase 通知正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38842230/