react-native - 按 ID 分组通知并像 Whatsapp 一样显示

标签 react-native firebase-cloud-messaging android-notifications firebase-notifications react-native-firebase

我一直在尝试按 id 对通知进行分组,例如将它们显示为 WhatsApp,而每行没有一个通知。

添加 setGroup在任一 onNotificationonNotificationDisplayed似乎没有效果见下面的例子:

1

componentDidMount() {
this.notificationListener = firebase.notifications().onNotification(async (notification) => {
  // Process your notification as required
  notification.android.setAutoCancel(true)

  notification.android.setGroup(notification.data.channelId)
  notification.android.setGroupSummary(true)
} 
}

2
componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
   notification.android.setGroup(notification.data.channelId)
  notification.android.setGroupSummary(true)
});
}

知道如何按 id 对它们进行分组吗?

最佳答案

这个怎么样:-

componentDidMount() {
    var zero = firebase.notifications().onNotification((notification) => {
        this.setState({
            channelId=notification.data.channelId,
            Title=notification.data.Title,
            Body=notification.data.Body
//basically get all the data from the notification the you receieve from notification into states.
        });
    });
    if(this.state.channelId === "WhatsApp"){
        this.notificationDisplayedListener = 
            notification.android.setAutoCancel(true)
            notification.android.setTitle(this.state.Title)
            notification.android.setBody(this.state.Body)
            notification.android.setGroup(this.state.channelId)
            notification.android.setGroupSummary(true)
    }
}

关于react-native - 按 ID 分组通知并像 Whatsapp 一样显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56518235/

相关文章:

android - 如何查看订阅了多少主题?

swift - 使用 FCM 的以下代码中我的错误在哪里?

ios - Firebase 刷新 token

android - 创建带有到期日期的 Android 通知

styling - 当它粘住时,React-Native 样式一个粘性标题

ios - iMessage 打字动画

react-native - 将输入重点放在 React Native 中的 Modal 负载上

javascript - Firestore - 如何在 native react 中通过 id 获取文档

android - 在关闭的应用程序中收到通知时转到特定 Activity ?

android: 从 Broadcastreceiver 调用函数: 无法启动接收器 ... java.lang.ClassCastException: android.app.ReceiveRestrictedContext