【问题标题】:How to clear firebase Push notification from status bar android programmatically如何以编程方式从状态栏android清除firebase推送通知
【发布时间】:2023-04-09 01:46:01
【问题描述】:

我可以使用此代码清除应用程序推送的通知

val notificationIds: MutableList<Int> = ArrayList()
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationIds.forEach {
    notificationManager.cancel(it)
}

它适用于我在每次通知时保存通知 ID
但现在我没有 Firebase 通知 ID

【问题讨论】:

    标签: android firebase kotlin push-notification android-notifications


    【解决方案1】:

    最好删除所有通知而不是保留通知 ID

    NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
    

    【讨论】:

      【解决方案2】:

      为此,您需要从 Firebase 发送数据消息,然后您可以手动创建带有 id 的通知。因此,您可以取消/清除通知。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-21
        • 1970-01-01
        相关资源
        最近更新 更多