如何从Android Firebase通知获取自定义数据? [英] How to get custom data from android firebase notification?
本文介绍了如何从Android Firebase通知获取自定义数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现Firebase通知.但是我很难找到有关如何从Firebase通知中检索自定义数据的任何文档.
I'm trying to implement firebase notifications. But I have trouble finding any documentation on how to retrieve custom data from firebase notification.
但是在代码中如何获取自定义密钥.
But in in code how to get the custom key.
我正在使用FirebaseMessagingService.onMessageReceived
来获取消息数据.
I'm using FirebaseMessagingService.onMessageReceived
to get the message data.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
推荐答案
您可以使用以下方法检查自定义数据:
You can check your custom data using:
for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Log.d(TAG, "key, " + key + " value " + value);
}
要获取特定密钥:
String value = remoteMessage.getData().get("<YOUR_KEY>");
这篇关于如何从Android Firebase通知获取自定义数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文