问题描述
我正在按照以下链接实现 Firebase 消息传递以将消息发送到多个设备
I'm following the below link to implement Firebase Messaging to send messages to multiple devices
https://firebase.google.com/docs/cloud-messaging/android/send-multiple#build_send_requests
我几乎完成了实现,但只是停留在最后阶段(构建发送请求)
I'm almost done with the implementation but just stuck at the last stage (Build send requests)
在下面的代码中
Message message = Message.builder() .putData("score", "850") .putData("time", "2:45") .setTopic(topic) .build();
我收到错误无法解析符号消息"
也行
String response = FirebaseMessaging.getInstance().send(message);
当我 Ctrl+单击 send() 方法时,参数 message 显示为 RemoteMessage 的实例,而不是返回的 Messagevoid 的类型而不是 String
When I Ctrl+click the send() method, the argument message is being shown as instance of RemoteMessage and not Message with return type of void and not String
我是否缺少任何依赖项,或者最新的 firebase 消息传递库中的实现是否有任何变化?
Am I missing any dependencies or is there any change in implementation in the latest library of firebase messaging?
我在我的应用级别 build.gradle
implementation 'com.google.firebase:firebase-messaging:19.0.1' implementation 'com.google.firebase:firebase-core:17.0.1'
推荐答案
Message 类在 Firebase ***** sdk 中,但你不能在你的 android 项目中使用它,你只能使用 firebase ***** sdk在服务器端,然后您将能够使用 Message 类.检查文档以供参考:-
The Message class is inside the Firebase ***** sdk but you cannot use that in your android project, you can only use firebase ***** sdk in the server side and then you will be able to use the Message class. Check the docs for reference:-
https://firebase.google.com/docs/cloud-messaging/管理主题
为了能够使用 ***** sdk,你需要一个像 Tomcat 这样的服务器,你也应该使用 java 版本 8,然后你可以按照以下教程进行操作:-
To be able to use the ***** sdk, you need a server like Tomcat, you should also use java version 8, then you can follow the following tutorial:-
https://firebase.google.com/docs/*****/setup/#先决条件
原答案
你需要使用RemoteMessage类,例如:
RemoteMessage message = RemoteMessage.builder() .addData("score", "850") .addData("time", "2:45") .build();
点击这里了解更多信息:
Check here for more information:
https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage
https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage.Builder.html