【问题标题】:Notifications - Clear all notifications in the android notification tray通知 - 清除 android 通知托盘中的所有通知
【发布时间】:2019-05-15 20:39:49
【问题描述】:

我正在向我的应用发送多个通知。我想要实现的是,每当用户单击一个通知时,通知托盘中的所有通知都会消失。

我试过添加

notification.android.setAutoCancel(true)

只对一个通知(被点击的那个)起作用

我也试过了:

firebase.notifications().removeAllDeliveredNotifications() 

没有任何作用。

我怎样才能做到这一点?

这是我的完整代码:

      componentDidMount() {
    firebase.notifications().removeAllDeliveredNotifications()

    this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
    });

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



    async componentWillMount() {
    this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
    });
    this.notificationListener = firebase.notifications().onNotification((notification) => {
    });

    this.notificationDisplayedListener();
    this.notificationListener();
    }

【问题讨论】:

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


    【解决方案1】:

    尝试移动删除通知的代码 (removeAllDeliveredNotifications()) 从onNotification 听众到onNotificationOpened 听众。当您尝试在到达时删除通知时,可能存在竞争条件。

    还因为您想在用户点击一个通知时清除通知。

    PS。将通知侦听器保留在 componentDidMountcomponentWillMount 中,而不是两者中。

    【讨论】:

    • 非常感谢!我已经厌倦了多次删除它(没有两个地方的听众)但是由于某种原因通知停止工作:|
    • 嘿,我也有同样的问题,你可以看看这个吗,@NishantNair stackoverflow.com/questions/57171787/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2015-04-24
    • 1970-01-01
    相关资源
    最近更新 更多