Notification - Customize Actions

Asked

Viewed 85 times

2

I wonder if it is possible to 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 the .addAction, it correctly loads the content.
But when I include it, it displays the default Notification layout.
Thanks in advance!

1 answer

1


How are you using a custom view as layout of the notification, instead of using addAction(), your layout shall provide buttons which, when clicked, will execute the 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.