通过ID对通知进行分组并显示类似Whatsapp的内容

Dan*_*inu 7 android-notifications react-native firebase-cloud-messaging 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)
} 
}
Run Code Online (Sandbox Code Playgroud)

2

componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
   notification.android.setGroup(notification.data.channelId)
  notification.android.setGroupSummary(true)
});
}
Run Code Online (Sandbox Code Playgroud)

知道如何按ID将它们分组吗?

Gáü*_*şhï 0

这个怎么样:-

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)
    }
}
Run Code Online (Sandbox Code Playgroud)