Android 正在进行的通知是不可接受的

Android 正在进行的通知是不可接受的,android,Android,我想显示一个不可撤销的通知,并且只在程序上延迟一段时间后才撤销它。我尝试了以下方法: RemoteViews bigView = new RemoteViews(context.getPackageName(), R.layout.big_notification); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .se

我想显示一个不可撤销的通知,并且只在程序上延迟一段时间后才撤销它。我尝试了以下方法:

RemoteViews bigView = new RemoteViews(context.getPackageName(),
            R.layout.big_notification);



    NotificationCompat.Builder builder = new 
   NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(text)
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCustomHeadsUpContentView(bigView)
            .setTicker("aaa")
            .setOngoing(true);


    notificationManager.notify(id, builder.build());
    removeNotification(notificationManager, id);
}

private static void removeNotification(final NotificationManager notificationManager, final int id) {
    Handler handler = new Handler();
    long delayInMilliseconds = 4000;
    handler.postDelayed(new Runnable() {
        public void run() {
            notificationManager.cancel(id);
        }
    }, delayInMilliseconds);
}
但是用户可以刷出通知…有什么想法吗?

试试这个:

notification.flags = Notification.FLAG_NO_CLEAR;