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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With