Notification - Custom Actions

2

I wonder if you can customize a Notification with your Actions. Example:

RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.customnotification);
Notification.Builder builder = new Notification.Builder(this) 
        .setSmallIcon(R.drawable.ic_ico)
        .setAutoCancel(true) 
        .setContentIntent(pIntent) 
        .setContent(remoteViews)
        .addAction(R.drawable.ic_sim, "Sim", intent)
        .addAction(R.drawable.ic_nao, "Não", outraIntent); 

When I remove .addAction , it loads the content correctly. Home But when I add it, it displays the default Notification layout. Home Thank you very much in advance!

    
asked by anonymous 05.06.2015 / 05:59

1 answer

1

As you are using a custom view as the of the notification, instead of using addAction() , your layout which, when clicked, will execute actions .

The intent's intent and outraIntent are assigned to these buttons as follows:

remoteViews.setOnClickPendingIntent(R.id.button1, intent);
remoteViews.setOnClickPendingIntent(R.id.button2, outraIntent);

See RemoteViews.setOnClickPendingIntent

    
05.06.2015 / 13:21