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

how to remove a persistent notification after setongoing(true)?

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

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