0

I can succesfully send Firebase cloud messages to my Android sample project. As described in here, I apply step 2 and it works so far.

My JSON body:

{
    "to": "/topics/testTopic",
    "data": {
        "key1" : "val1",
        "key2" : true
     }
}

has a data field which I can access properly in my onMessageReceived() method:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String toVal = remoteMessage.getTo();
    Map<String, String> data = remoteMessage.getData();
}

But the getTo() method gets null. How can I access the 'to' field in my originating JSON?

I was expecting to have "/topics/testTopic" in im variable toVal.

Murat Ceven
  • 264
  • 1
  • 6

1 Answers1

0

I think you're looking for RemoteMessage.getFrom():

Get the sender of this message.

This will be the sender ID or the topic for topic messages.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281