1

A similar question has been asked here but it got no answer. I am trying to send device to device notification using FCM and using the code mentioned in the official Firebase sample from github :

public void sendToToken() throws FirebaseMessagingException {
        // [START send_to_token]
        // This registration token comes from the client FCM SDKs.
        String registrationToken = YOUR_REGISTRATION_TOKEN;

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

        // Send a message to the device corresponding to the provided
        // registration token.
        String response = FirebaseMessaging.getInstance().send(message);
        // Response is a message ID string.
        System.out.println("Successfully sent message: " + response);
        // [END send_to_token]
    }

But while running the app, I'm receiving this error :

error: incompatible types: Message cannot be converted to RemoteMessage
Ssubrat Rrudra
  • 870
  • 8
  • 20
  • check my answer here: https://stackoverflow.com/questions/57059108/cannot-resolve-symbol-com-google-firebase-messaging-message/57063431#57063431 – Peter Haddad Jul 17 '19 at 10:12
  • 1
    As Peter said in his linked answer, the class you're using is part of the Firebase Admin SDK which cannot be used in Android apps. There is no way to send direct device to device messages with just FCM, since sending messages *to* a device requires that you specify the FCM server key, which (as its name implies) should only be used on a server, or otherwise trusted environment. Also see https://stackoverflow.com/a/39279716, https://stackoverflow.com/a/56552374, and https://stackoverflow.com/a/37993724. – Frank van Puffelen Jul 17 '19 at 13:38

1 Answers1

1

You have wrong import for Message object.Import bellow message

import com.google.firebase.messaging.RemoteMessage;

Use

RemoteMessage message = new RemoteMessage(bundle);
Hardik Bambhania
  • 1,732
  • 15
  • 25
  • but I'm importing com.google.messaging.Message successfully and not getting any error while importing. And these codes are copy-pasted from firebase documentation. – Ssubrat Rrudra Jul 17 '19 at 09:52