gpt4 book ai didi

android - 如何在 setongoing(true) 之后删除持久通知?

转载 作者:太空狗 更新时间:2023-10-29 13:03:02 26 4
gpt4 key购买 nike

这是我用来在 Android 中创建通知的代码。此通知按预期显示,不会通过滑动通知来删除。但我无法以编程方式删除它。我应该如何删除它?

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), Constants.CHANNEL_ID)
.setSmallIcon(R.drawable.small)
.setContentTitle("persistent")
.setContentText("cant remove").setOngoing(true);
mBuilder.build();

最佳答案

在这个答案中有一个关于如何做的很好的解释: https://stackoverflow.com/a/19268653/3853450

在你的情况下应该是这样的:

NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.CHANNEL_ID);

此外,如原始答案中所述:

NotificationManager

关于android - 如何在 setongoing(true) 之后删除持久通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52875612/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com