Android - Botones en barra de notificacion android

 
Vista:
sin imagen de perfil

Botones en barra de notificacion android

Publicado por Marcel (1 intervención) el 14/01/2017 22:40:55
Buenos dias!

He creado una notificacion con un par de botones, y quiero que cuando se pulse sobre el botón se ejecute una funcion, tipo los reproductores de musica, que tienen los botones de play y pause.

Todo lo que he encontrado referente a esos botones son intent y pendint intent, que lanzar una activity, y yo simplemente quiero que se ejecute una funcion sin que se abre ninguna aplicacion.

Esta funcion lanza la notificacion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public void LanzarNotifacion(){
    android.support.v4.app.NotificationCompat.Builder mBuilder =
        null;
 
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        mBuilder = new NotificationCompat.Builder(Capturadora.this)
        .setSmallIcon(android.R.drawable.stat_sys_warning)
        .setCategory(CATEGORY_SERVICE)
        .setPriority( PRIORITY_HIGH )
        .setLargeIcon( ((BitmapDrawable)getDrawable( R.drawable.ic_action_stat_reply)).getBitmap() )
        .setContentTitle("Capturadora")
        .setContentText("¡Captura!")
        .setContentInfo("")
        .setOngoing(true)
        .setTicker("SuperApp!");
 
 
    }
 
    setButtons( mBuilder );
    Intent notIntent =
    new Intent(Capturadora.this, Capturadora.class);
 
    PendingIntent contIntent = PendingIntent.getActivity(
            Capturadora.this, 0, notIntent, 0);
 
    mBuilder.setContentIntent(contIntent);
 
    mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 
    mNotificationManager.notify(NOTIF_ALERTA_ID, mBuilder.build());
 
}

Esta añade los botones

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
private void setButtons(android.support.v4.app.NotificationCompat.Builder builder) {
 
 
//estos son los intent que quiero que ejecuten la funcion
    Intent dd =
            new Intent(Capturadora.this, Capturadora.class);
 
    Intent pause =
            new Intent(this, Pause.class);
 
//y este el pending item, que en la documentacion tampoco vi como cambiarlo
    PendingIntent playIntent = PendingIntent.getActivity(
            Capturadora.this, 0, dd, 0);
 
 
    PendingIntent pauseIntent = PendingIntent.getActivity(
            this, 0, pause, 0);
 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.addAction(android.R.drawable.ic_media_play, "Play", playIntent);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.addAction(android.R.drawable.ic_media_pause, "Pause", pauseIntent);
    }
 
 
}



Espero que podais ayudarme. Muchas gracias
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