Android - boton de accion en una notificacion en android studio kotlin

 
Vista:
sin imagen de perfil
Val: 2
Ha disminuido su posición en 51 puestos en Android (en relación al último mes)
Gráfica de Android

boton de accion en una notificacion en android studio kotlin

Publicado por Lian (2 intervenciones) el 01/02/2021 20:00:52
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

boton de accion en una notificacion en android studio kotlin

Publicado por Lian (2 intervenciones) el 03/02/2021 19:49:30
ya resolvi con este codigo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
1
2
3
4
5
6
7
8
9
10
11
12
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()
    }
}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar