0

I am following this guide for sending messages to some devices. The part about building a sending request, it says:

// 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);

When I try to import the Message class, the IDE tells me that there is no library, why?

Maybe it is deprecated but the documentation has not been updated?

Thanks

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
gyorgio88
  • 457
  • 1
  • 5
  • 8

1 Answers1

1

The code you copied is using the Firebase Admin SDK for Java, and cannot be used on Android. From the documentation you linked:

After you have created a topic, either by subscribing client app instances to the topic on the client side or via the server API, you can send messages to the topic. If this is your first time building send requests for FCM, see the guide to your server environment and FCM for important background and setup information.

It is not possible to directly send messages from one device to another device. You will always need a server (or otherwise trusted environment) for this. For more on this, see the linked documentation and:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807