如何知道 Android 中 Firebase 通知中的主题名称?

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

我正在开发一个集成了 Firebase 来处理通知的应用程序。我只想知道如何获取从后端团队发送给我的主题名称。其中包含三个主题,根据主题,我必须以不同的布局显示消息。我得到这样的标题和 body:

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

在你的 onMessageReceived() 中,只需使用 RemoteMessage.getFrom():

Get the sender of this message.

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

如果收到的消息来自某个主题,它应该return主题名称的值。