Vishal Afre
Vishal Afre

Reputation: 1043

Cannot resolve symbol com.google.firebase.messaging.Message

I'm following the below link to implement Firebase Messaging to send messages to multiple devices

https://firebase.google.com/docs/cloud-messaging/android/send-multiple#build_send_requests

I'm almost done with the implementation but just stuck at the last stage (Build send requests)

In the below code

Message message = Message.builder()
    .putData("score", "850")
    .putData("time", "2:45")
    .setTopic(topic)
    .build();

I'm getting the error Cannot resolve symbol 'Message'

Also in the line

String response = FirebaseMessaging.getInstance().send(message);

When I Ctrl+click the send() method, the argument message is being shown as instance of RemoteMessage and not Message with return type of void and not String

Am I missing any dependencies or is there any change in implementation in the latest library of firebase messaging?

I'm using the following (latest) Firebase version in my app level build.gradle

implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-core:17.0.1'

Upvotes: 0

Views: 8192

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80904

The Message class is inside the Firebase admin sdk but you cannot use that in your android project, you can only use firebase admin sdk in the server side and then you will be able to use the Message class. Check the docs for reference:-

https://firebase.google.com/docs/cloud-messaging/manage-topics

To be able to use the admin sdk, you need a server like Tomcat, you should also use java version 8, then you can follow the following tutorial:-

https://firebase.google.com/docs/admin/setup/#prerequisites


Original Answer

You need to use RemoteMessage class, example:

RemoteMessage message = RemoteMessage.builder()
    .addData("score", "850")
    .addData("time", "2:45")
    .build();

Check here for more information:

https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage

https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage.Builder.html

Upvotes: 2

Related Questions