首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通知-清除android通知托盘中的所有通知

通知-清除android通知托盘中的所有通知
EN

Stack Overflow用户
提问于 2019-05-16 04:39:50
回答 1查看 969关注 0票数 5

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

我试着添加了

代码语言:javascript
复制
notification.android.setAutoCancel(true)

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

我也尝试过:

代码语言:javascript
复制
firebase.notifications().removeAllDeliveredNotifications() 

不会有任何效果。

我如何才能做到这一点?

下面是我的完整代码:

代码语言:javascript
复制
      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();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-09 13:51:57

尝试将用于删除通知(removeAllDeliveredNotifications())的代码从onNotification侦听器移动到onNotificationOpened侦听器。可能存在竞争条件,因为您正在尝试删除到达时的通知。

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

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56157296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档