简体   繁体   中英

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();
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM