0

I'm trying to send a notification to my Android device using my Java Server with the FireBase Admin SDK.

I can send test notifications from the FireBase website successfully, but I'm having trouble setting it up on Java in my server:

    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();
    }

I get this error:

Exception in thread "main" java.lang.IllegalArgumentException: Exactly one of token, topic or condition must be specified

Where do I even set the user token here? I just want to send a simple notification using FireBase in Java to my Android FireBase client.

Ran Shorowitz
  • 307
  • 5
  • 11
  • https://stackoverflow.com/questions/60170040/firebase-admin-sdk-fcm-error-exactly-one-of-topic-token-or-condition-is-require – SkywalkerLuke JS Jan 14 '22 at 10:17
  • @SkywalkerLukeJS I don't think there's a solution in there to my code. I'm trying to send a notification, not a message. Also that person is using NodeJS, not Java. – Ran Shorowitz Jan 14 '22 at 19:37

1 Answers1

0

Just had to put .setToken(...) after the line: build())

I was putting it in the wrong place.

Ran Shorowitz
  • 307
  • 5
  • 11