Ответ 1
При построении Notification
на NotificationBuilder
вы можете использовать notificationBuilder.setAutoCancel(true);
.
Если возникли проблемы с уведомлением, которое я хочу показать в панели уведомлений. Хотя я установил флаг уведомления Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL
, уведомление не исчезает после нажатия на него. Любые идеи, что я делаю неправильно?
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence tickerText = "Ticker Text";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, time);
notification.flags = Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL;
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, SilentFlipConfiguration.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1,notification);
При построении Notification
на NotificationBuilder
вы можете использовать notificationBuilder.setAutoCancel(true);
.
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
Из документации:
Бит быть побитовым - или ed в поле флагов, которое должно быть установлено если уведомление должно быть отменено при нажатии пользователем
// 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)
.
Источник: https://developer.android.com/reference/android/app/Notification.Builder.html
Используйте флаг Notification.FLAG_AUTO_CANCEL
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(контекст, contentTitle, contentText, pendingIntent);
//Отмена уведомления после его выбора 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);