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).
Adding an action button: It is similar to setting the tap action by creating a pending intent only change is that we set it using addAction() to attach it to the notification. We can create intents for both activities or broadcast receivers as shown below: You can create your own BroadcastReciever.
You can create an intent for the action (in this case stop playing) and then add it as an action button to your notification. Intent snoozeIntent = new Intent(this, MyBroadcastReceiver. class); snoozeIntent. setAction(ACTION_SNOOZE); snoozeIntent.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With