[英]How to clear firebase Push notification from status bar android programmatically
I can clear the notification that is pushed from the app with this code我可以使用此代码清除从应用程序推送的通知
val notificationIds: MutableList<Int> = ArrayList()
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationIds.forEach {
notificationManager.cancel(it)
}
it works with when I save notification Id at every notify它适用于我在每次通知时保存通知 ID
but now I didn't have firebase notification id但现在我没有 firebase 通知 ID
Better to Delete All Notifications rather to keep notification id最好删除所有通知而不是保留通知 ID
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
For this, you need to send data messages from Firebase and with that you can create notification with id manually.为此,您需要从 Firebase 发送数据消息,然后您可以手动创建带有 id 的通知。 Hence, you would be able to cancel/clear notification.
因此,您将能够取消/清除通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.