0

Hola amigos quiero que mi notificacion tenga un boton Actualizar que cuando lo oprima este ejecute un metodo y actualice el contenido de la notificacion, sale el boton pero cuando le doy no ejecuta nada, este es mi codigo, pero no entiendo como hacer que funcione

    val snoozeIntent = Intent(this, MainActivity::class.java).apply {
        action = "" //<- aqui es donde no se que poner para que me ejecute el metodo
        putExtra(EXTRA_NOTIFICATION_ID, 0)            
    }
    val snoozePendingIntent: PendingIntent =
        PendingIntent.getBroadcast(this, 0, snoozeIntent, 0)

    var builder = NotificationCompat.Builder(this, "default")
        .setSmallIcon(R.drawable.ic_notificacion)            
        .setOnlyAlertOnce(true)
        .setVisibility(NotificationCompat.VISIBILITY_SECRET)
        .setOngoing(true)
        .setColor(resources.getColor(R.color.colorAccent))
        .setStyle(
            NotificationCompat.BigTextStyle()
                .bigText(TEXT)
        )
        .addAction(R.drawable.ic_notificacion, "Actualizar",
            snoozePendingIntent)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setContentIntent(pendingIntent)
        .setAutoCancel(true)

1 respuesta 1

0

ya resolvi con este codigo

val snoozeIntent = Intent(cont, NotificationReceiver::class.java).apply {            
        putExtra(Notification.EXTRA_NOTIFICATION_ID, 0) 
    }
    val snoozePendingIntent: PendingIntent =
        PendingIntent.getBroadcast(cont, 0, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT)


    var builder = NotificationCompat.Builder(cont, "default")
        .setSmallIcon(R.drawable.ic_notificacion)            
        .setOnlyAlertOnce(true)
        .setVisibility(NotificationCompat.VISIBILITY_SECRET)
        .setOngoing(true)
        .setColor(cont.resources.getColor(R.color.colorAccent))
        .setStyle(
            NotificationCompat.BigTextStyle()
                .bigText(TEXT)
        )
        .setContentIntent(pendingIntent)
        .addAction(R.drawable.ic_notificacion, "Actualizar",
            snoozePendingIntent)            
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setCategory(NotificationCompat.CATEGORY_MESSAGE)
        .setAutoCancel(true)

y la clase

class NotificationReceiver: BroadcastReceiver() {
private lateinit var dato:Datos
override fun onReceive(context: Context?, intent: Intent?) {
    
    if (intent!=null){           

        dato = context?.let { Datos(context) }!!

        dato.actualizarnotificacion()
    }
}

}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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