如何清除通知操作点击通知?

时间:2018-02-24 14:10:56

标签: java android notifications

我正在开发一个Android应用程序,我用动作显示通知。但是在行动点击通知没有清除,它陷入了阴影。如何清除有关操作点击的通知?

我的代码

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
Intent intent = new Intent(this, SettingsActivity.class);
PendingIntent openSettingsActivity = PendingIntent.getActivity(this,1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder.addAction(R.drawable.ic_notification_button, "Settings", openSettingsActivity);
notificationBuilder.setPriority(Notification.PRIORITY_MAX);
notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
notificationBuilder.setContentTitle(title);
                notificationBuilder.setContentText(text);
                notificationBuilder.setAutoCancel(true);
                notificationBuilder.setColor(color);
                notificationBuilder.setSmallIcon(R.drawable.ic_notification);
                notificationBuilder.setContentIntent(openSettingsActivity);
                final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1,notificationBuilder.build());

1 个答案:

答案 0 :(得分:0)

从通知中删除此标志,FLAG_AUTO_CANCEL会在用户触摸时自动解除通知。

notification.flags&=Notification.FLAG_AUTO_CANCEL;

还要检查"Notification setAutoCancel(true) doesn't work"