Cannot resolve symbol com.google.firebase.messaging.Message(无法解析符号 com.google.firebase.messaging.Message)
问题描述
我正在按照以下链接实现 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 admin sdk 中,但你不能在你的 android 项目中使用它,你只能使用 firebase admin sdk在服务器端,然后您将能够使用 Message 类.检查文档以供参考:-
The Message class is inside the Firebase admin sdk but you cannot use that in your android project, you can only use firebase admin 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/管理主题
为了能够使用 admin sdk,你需要一个像 Tomcat 这样的服务器,你也应该使用 java 版本 8,然后你可以按照以下教程进行操作:-
To be able to use the admin 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/admin/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
这篇关于无法解析符号 com.google.firebase.messaging.Message的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法解析符号 com.google.firebase.messaging.Message
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
