无法取消android中的通知

无法取消android中的通知,android,android-notifications,Android,Android Notifications,我有一个问题,当用户按下时,通知活动打开,但无法关闭 这是我的密码: NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; CharSequence tickerText = "Good Morning";

我有一个问题,当用户按下时,通知活动打开,但无法关闭

这是我的密码:

NotificationManager mNotificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.ic_launcher;
    CharSequence tickerText = "Good Morning";
    long time = System.currentTimeMillis();
    Notification notification = new Notification(icon, tickerText, time);
    Context context = getApplicationContext();
    CharSequence contentTitle = "Title";
    CharSequence contentText = "Text";
    Intent notificationIntent = new Intent(this, NotificationManagerDemoActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,0);
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(1,notification);

像这样试试,希望能奏效。。
notification.flags |=notification.FLAG_AUTO_CANCEL

在生成
通知时将自动取消设置为true,如下所示

  notificationBuilder.setAutoCancel(true);

您应该尝试编写如下代码

NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(getApplicationContext(), "Channel")
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                     R.mipmap.ic_launcher_logo_round))
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.mipmap.ic_launcher_logo_round);
mNotificationManager.notify(id,mBuilder.build());
.setAutoCancel(true) 

请在你的代码中添加注释。具体写什么?一切都很清楚。要更改通知设置,您需要通过Builder重新生成通知。如果您知道通知未关闭的原因,可以尝试。