Android: eliminar notificación de la barra de notificaciones
He creado una aplicación y con un evento logro agregar notificación en la barra de notificación de Android. ¿Ahora necesito la muestra cómo quitar esa notificación de la barra de la notificación en un acontecimiento ??
- Pin Notificación a la parte superior del área de notificación
- ¿Cómo puedo activar las vibraciones y las luces con la API de notificaciones de Android?
- NotificationListenerService: NullPointerException en getActiveNotifications
- Icono de servicio persistente en la barra de notificaciones
- Cómo abrir la misma actividad después de hacer clic en las notificaciones de diferencias
- Notifications.Builder en API 10
- Android lolipop notificación blanco círculo vacío
- Congelación de la barra de progreso de la notificación de Android
- Notificación de color de texto en Galaxy S 2.3.3
- Cómo enviar una notificación desde el servidor PHP a la aplicación Android
- Notificación no mostrada cuando setGroup () se llama en Android KitKat
- Generador de notificaciones en android 2.3
- Reproducir sonido en las notificaciones de Android, aunque el modo de silencio del teléfono se establece
Esto es bastante simple. Usted tiene que llamar cancel
o cancel
cancelAll
en su NotificationManager. El parámetro del método de cancelación es el ID de la notificación que se debe cancelar.
Consulte la API: http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)
Puedes probar este código rápido
public static void cancelNotification(Context ctx, int notifyId) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nMgr = (NotificationManager) ctx.getSystemService(ns); nMgr.cancel(notifyId); }
También puede llamar a cancelAll
en el administrador de notificaciones, por lo que ni siquiera tiene que preocuparse por los ids de notificación.
NotificationManager notifManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notifManager.cancelAll();
EDIT: Yo estaba downvoted por lo que tal vez debería especificar que esto sólo se eliminará la notificación de su aplicación.
Simplemente establezca setAutoCancel (True) como el código siguiente:
Intent resultIntent = new Intent(GameLevelsActivity.this, NotificationReceiverActivityAdv.class); PendingIntent resultPendingIntent = PendingIntent.getActivity( GameLevelsActivity.this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT ); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( getApplicationContext()).setSmallIcon(R.drawable.icon) .setContentTitle(adv_title) .setContentText(adv_desc) .setContentIntent(resultPendingIntent) //HERE IS WHAT YOY NEED: .setAutoCancel(true); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(547, mBuilder.build());`
Si está generando la notificación de un servicio que se inicia en primer plano mediante
startForeground(NOTIFICATION_ID, notificationBuilder.build());
Luego emitir
notificationManager.cancel(NOTIFICATION_ID);
No funciona la cancelación de la notificación y notificación sigue apareciendo en la barra de estado. En este caso particular, usted resolverá estos de 2 maneras:
1> Utilizar stopForeground (false) dentro del servicio:
stopForeground( false ); notificationManager.cancel(NOTIFICATION_ID);
2> Destruye esa clase de servicio con actividad de llamada:
Intent i = new Intent(context, Service.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); if(ServiceCallingActivity.activity != null) { ServiceCallingActivity.activity.finish(); } context.stopService(i);
Segunda manera prefieren en la notificación de reproductor de música más porque thay forma no sólo la notificación de eliminar pero eliminar jugador también … !!
esto ayudará:
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager.cannelAll();
Y si crea una notificación llamando
startForeground();
Dentro de un Servicio. Es posible que tenga que llamar
stopForeground(false);
Primero, luego cancele la notificación.
Utilice NotificationManager para cancelar su notificación. Sólo necesita proporcionar su ID de notificación
MNotificationManager.cancel (YOUR_NOTIFICATION_ID);
También verifica este enlace
- Mostrar icono en barra de herramientas / barra de herramientas con AppCompat-v7 21
- Diferencia entre un ImageView y ImageButton que puede hacer clic