首页 文章

如何通知通知聚合

提问于
浏览
4

我的应用程序显示事件通知,我正在寻找一种方法来进行通知聚合 . 意思是,我想显示4个通知,但如果第五个通知,我想收集所有通知并只显示一个一般通知 .

有没有办法知道我有多少实时通知?是否有可能接近这些通知并取消它们?

谢谢!

1 回答

  • 0

    根据android设计guidelines你应该堆叠你的通知 . 因此,您应该避免为同一个应用显示多个通知 .

    您可以使用堆叠通知

    NotificationManager.notify(ID, notification) 您为每个通知指定相同的ID .

    您可以查看docs如何实现它 .

    对于你的情况

    Is there a way to know how many live notifications i have - No
    

    但您可以使用“共享首选项”跟踪通知,您可以在其中存储通知的ID,并在用户单击通知时将其删除

    Is it possible to approach these notification and cancel them? - Yes
    

    您可以使用 cancel(int id) 方法取消通知,您可以在其中传递要删除的通知的ID .

    因此,您可以使用此方法来实现您想要的内容,但建议堆叠所有通知 .

相关问题