我正在开发一个集成了 Firebase 来处理通知的应用程序。我只想知道如何获取从后端团队发送给我的主题名称。其中包含三个主题,根据主题,我必须以不同的布局显示消息。我得到这样的标题和正文:
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.
如果收到的消息来自主题,它应该返回主题名称的值。
关于android - 如何知道 Android 中 Firebase 通知中的主题名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48415951/