1

Estoy tratando de implementar notificaciones locales para mi App.

Las notificaciones aparecen y funcionan bien, el problema viene a la hora de borrarlas de la "feed", estas se quedan ahí como bloqueadas, por mucho que deslice el dedo sobre estas no desaparecen.

NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);

//CREO LA NOTIFICACION
Notification.Builder oNotBuilder = new Notification.Builder(this)
.SetContentTitle(Resources.GetString(Resource.String.app_name))
.SetContentText(mensaje)
.SetSmallIcon(Resource.Drawable.res)
.SetAutoCancel(true);

//CREO EL INTENT
Intent intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop);

//ESTO TODAVIA NO ESTOY SEGURO DE PARA QUE SIRVE
PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

//CONSTRUYO LA NOTIFICACION
oNotBuilder.SetContentIntent(pendingIntent);
oNotBuilder.SetOngoing(true).SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
oNotBuilder.SetDefaults(NotificationDefaults.All);
oNotBuilder.SetVibrate((new long[] { 1000, 1000, 1000, 1000, 1000 }));

Notification ntf = oNotBuilder.Build();

//ESTO SE SUPONE QUE PERMITE QUE CANCELE LA NOTIFICACION, pero no.
notificationManager.Cancel(NOTIFICATION_ID);


//HAGO SPAM DE NOTIFICACIONES (por que tiene que ser insistente)
repetirNotificacion = true;
while (repetirNotificacion)
{
     notificationManager.Notify(NOTIFICATION_ID, ntf);
     //StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, ntf);
     Thread.Sleep(5 * 1000);

}
//Incremento el id de notificacion.
NOTIFICATION_ID += 1;

Se supone que el notificationManager.Cancel(true); permite cancelar la notificacion haciéndola desaparecer de la feed, pero no. Pensé que sería algo así como una propiedad un setCancel o similar pero no se comporta como esperaba.

También he probado a ponerlo fuera del bucle, pero me parece que eso no es lo que estoy buscando.

1 respuesta 1

1

Se que es tarde de responder pero tu problema esta al construir la notificación ya que agregas oNotBuilder.SetOngoing(true) lo cual hace que tu notificación no pueda ser cancelada, quita esa parte y se solucionará.

1
  • 1
    Gracias, el lunes pruebo y te digo :)
    – Aritzbn
    el 6 abr. 2019 a las 13:33

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.