Android 如何在setContinuous(true)之后删除持久通知?
下面是我用来在Android中创建通知的代码。此通知按预期显示,不会通过滑动通知而被删除。 但我无法以编程方式删除它。我应该如何删除它Android 如何在setContinuous(true)之后删除持久通知?,android,android-notifications,Android,Android Notifications,下面是我用来在Android中创建通知的代码。此通知按预期显示,不会通过滑动通知而被删除。 但我无法以编程方式删除它。我应该如何删除它 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), Constants.CHANNEL_ID) .setSmallIcon(R.drawable.small)
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), Constants.CHANNEL_ID)
.setSmallIcon(R.drawable.small)
.setContentTitle("persistent")
.setContentText("cant remove").setOngoing(true);
mBuilder.build();
在这个答案中,有一个很好的解释说明了如何做到这一点: 在您的情况下,应该是这样的:
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.CHANNEL_ID);
此外,如原始答案所示:
感谢信的可能副本。我用notificationManager.notify(id,mBuilder.build())完成了它;发送通知并使用您提供的代码将其删除notificationManager.cancel(id);很乐意帮忙D