【问题标题】:FireBase Admin SDK Java: Sending a notificationFireBase Admin SDK Java:发送通知
【发布时间】:2022-01-15 03:39:46
【问题描述】:

我正在尝试使用带有 FireBase Admin SDK 的 Java 服务器向我的 Android 设备发送通知。

我可以从 FireBase 网站成功发送测试通知,但在我的服务器中的 Java 上设置它时遇到问题:

    Message message = Message.builder()
    .setNotification(Notification.builder()
        .setTitle("$GOOG up 1.43% on the day")
        .setBody("$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")
        .build())
    .build();


    // Send a message to the device corresponding to the provided
    // registration token.
    String response = "N/A";
    try {
        response = FirebaseMessaging.getInstance().send(message);
    } catch (FirebaseMessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

我收到此错误:

线程“main”java.lang.IllegalArgumentException 中的异常:必须指定令牌、主题或条件中的一个

我什至在哪里设置用户令牌?我只想使用 Java 中的 FireBase 向我的 Android FireBase 客户端发送一个简单的通知。

【问题讨论】:

标签: java android firebase push-notification


【解决方案1】:

只需将 .setToken(...) 放在以下行之后:build())

我放错地方了。

【讨论】:

    猜你喜欢
    • 2020-06-28
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 2023-02-01
    相关资源
    最近更新 更多