【问题标题】:How to know which topic name in Firebase Notification in Android?如何知道 Android 的 Firebase 通知中的哪个主题名称?
【发布时间】:2018-07-03 02:42:38
【问题描述】:

我正在开发一个集成了 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();
    }
}

【问题讨论】:

  • 通知如何在远程消息中发送主题。
  • { "message":{ "topic" : "foo-bar", "notification" : { "body" : "这是 Firebase 云消息传递主题消息!", "title" : " FCM 消息”,} } }
  • 是的,我知道这个@RatilalChopda 实际上看到了获取正文和标题我们写 String title = remoteMessage.getNotification().getTitle();字符串正文 = remoteMessage.getNotification().getBody();但是要获取主题,没有像 remoteMessage.getTopic() 这样的方法

标签: android firebase firebase-cloud-messaging android-notifications


【解决方案1】:

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

获取此消息的发件人。

这将是主题消息的发件人 ID 或主题。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 2017-07-12
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    相关资源
    最近更新 更多