【问题标题】:Lack of some classes in the firebase-messaging( vers. 21) library (JAVA)firebase-messaging(第 21 版)库 (JAVA) 中缺少某些类
【发布时间】:2021-02-28 18:15:03
【问题描述】:

我正在关注guide 向某些设备发送消息。 关于构建发送请求的部分,它说:

// The topic name can be optionally prefixed with "/topics/".
String topic = "highScores";

// See documentation on defining a message payload.
Message message = Message.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .setTopic(topic)
    .build();

// Send a message to the devices subscribed to the provided topic.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

当我尝试导入 Message 类时,IDE 告诉我没有库,为什么?

也许它已被弃用但文档尚未更新?

谢谢

【问题讨论】:

    标签: java android firebase firebase-cloud-messaging firebase-notifications


    【解决方案1】:

    您复制的代码使用的是 Firebase Admin SDK for Java,无法在 Android 上使用。从您链接的文档中:

    创建主题后,通过在客户端订阅客户端应用程序实例或通过server API,您可以向该主题发送消息。如果这是您第一次为 FCM 构建发送请求,请参阅your server environment and FCM 的指南了解重要的背景和设置信息。

    无法将消息从一台设备直接发送到另一台设备。为此,您将始终需要服务器(或其他受信任的环境)。有关这方面的更多信息,请参阅链接文档和:

    【讨论】:

    • 抱歉,我匆忙错过了一些细节。谢谢
    猜你喜欢
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 2016-12-20
    相关资源
    最近更新 更多