13
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.schedule) .addAction(R.drawable.icon,"action test",pi) .setStyle(new NotificationCompat.BigTextStyle().bigText(body)) .setContentTitle(title) .setContentText(body); 

Above code creates notification and adds one action (button) to it. I want my button to be without icon displayed, but I don't know how to do that, because icon in parameter addAction is required and not nullable.

Is it even possible to add action button to notification without any icon (btw, icons on action buttons seems to be not even shown on Nougat an Oreo).

1 Answer 1

30

Use NotificationCompat.Action instead. And set 0 as the value for icon

NotificationCompat.Action action = new NotificationCompat.Action.Builder( 0, "action test", pi ).build(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.schedule) .addAction(action) .setStyle(new NotificationCompat.BigTextStyle().bigText(body)) .setContentTitle(title) .setContentText(body); 

Worked all the devices as far I have tested

Sign up to request clarification or add additional context in comments.

3 Comments

I guess addAction(0,"action test",pi) should be the same, looking at source code it internally calls addAction(new Action(icon, title, intent)) but I was not sure if I can pass 0 as resource id
weird to pass 0 instead of null, but ok
int cant be null

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.