Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know which topic name in Firebase Notification in Android?

I am working on an application in which I have integrated Firebase to handle the notification. I just want to know how I can get the topic name which is sent from backend team to me. There are three topics in that and according to topics, I have to show the message in a different layout. I am getting title and body like this:

    if (remoteMessage.getData().size() > 0) {
        //handle the data message here
    try {
        String title = remoteMessage.getNotification().getTitle();
        String body = remoteMessage.getNotification().getBody();
        Log.e("TITLE AND BODY", title + "\n" + body);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
like image 870
Sekhar Avatar asked Jan 24 '18 06:01

Sekhar


1 Answers

In your onMessageReceived(), just use RemoteMessage.getFrom():

Get the sender of this message.

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

It should return the value of the topic name if the message received was from a topic.

like image 153
AL. Avatar answered Nov 12 '22 00:11

AL.