gpt4 book ai didi

android - FCM onReceivedMessage() 获取 Bundle

转载 作者:行者123 更新时间:2023-11-29 19:14:28 26 4
gpt4 key购买 nike

link of structure

我正在尝试从我的 ArrayMap 获取消息,但我无法访问 ReceiveMessage 包。我尝试直接访问Map,但是非常错误

我的代码

public class FbService extends FirebaseMessagingService {
public FbService() {
}

@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.

Map<String, String> params = remoteMessage.getData();
String message = params.get(3);

Log.d("FbService", "Notification Message Body: " + message);



}
}

最佳答案

感谢@Pritish Joshi

我找到了这个答案,对我帮助很大, 这是代码 fragment

获取Map形式的数据

public void onMessageReceived(RemoteMessage remoteMessage)
{
Log.e("dataChat",remoteMessage.getData().toString());
try
{
Map<String, String> params = remoteMessage.getData();
JSONObject object = new JSONObject(params);
Log.e("JSON_OBJECT", object.toString());
}
}

确保从服务器发送的数据格式正确,即在“数据”键中

这是演示 Json 文件

{
"to": "registration_ids",
"data": {
"key": "value",
"key": "value",
"key": "value",
"key": "value"
}
}

引用:

关于android - FCM onReceivedMessage() 获取 Bundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44101503/

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