Pregunta

Estoy mostrando un Notification en la barra de estado dependiendo de mi condición. Hasta esto, está bien.

Ahora el problema en mi aplicación es cuando vuelvo a la aplicación, sigue siendo el Notification se muestra en la barra de estado.

No quiero el Notification Cuando regrese de la aplicación. Porque esto me da algunas sugerencias.

¿Fue útil?

Solución

Puedes cancel() tu propio Notifications mediante el NotificationManager. Depende de usted decidir cuándo cancel() Es y cuándo mostrarlo.

Otros consejos

No tengo suficiente representante para agregar comentarios, así que @commonware. . . Sería más útil para futuros lectores si dio detalles más específicos como decirles que usen un "ID de notificación" Cuando crean la notificación y usan esa identificación para cancelar la notificación. Si da una respuesta, haga que complete o al menos proporcione los detalles completos. Estas publicaciones no solo están destinadas a la OP, también ayuda a otros que se encuentran con esta publicación. al igual que

final NotificationManager notificationManager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE);

final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);

Luego para cancelarlo llamas

notificationManager.cancel(NOTIFICATION_ID);

o puedes llamar

notificationManager.cancelAll();
notificationManager.cancelAll();
private void cancelNotificationInBar() {
        NotificationCreator notification = new NotificationCreator(getApplicationContext());
        notification.mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        if (notification.mNotificationManager != null) {
            notification.mNotificationManager.cancelAll();
        }
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top