notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
从文档:
有点位 - 要么 加入应该设置的标志字段 如果通知应在用户点击时取消
使用标志Notification.FLAG_AUTO_CANCEL
Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); // Cancel the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL;
并启动应用程序:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(context, App.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, intent_id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Uses the default lighting scheme notification.defaults |= Notification.DEFAULT_LIGHTS; // Will show lights and make the notification disappear when the presses it notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
2016状态:你可以使用 mBuilder.setAutoCancel(true) 。
mBuilder.setAutoCancel(true)
资源: https://developer.android.com/reference/android/app/Notification.Builder.html
建设时 Notification 通过 NotificationBuilder 您可以使用 notificationBuilder.setAutoCancel(true); 。
Notification
NotificationBuilder
notificationBuilder.setAutoCancel(true);
我的答案是使用 mBuilder.setOngoing(false)
mBuilder.setOngoing(false)