Steve M
Steve M

Reputation: 9784

Make Action icons appear when notification is collapsed

I currently add two actions which appear as buttons when the notification is expanded. They do not appear when the notification is collapsed as per the documentation. Some apps present the buttons when the notification is collapsed as well (see Google Play Music below). How do I make my notification do that?

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context)
                .setSmallIcon(R.drawable.notification_isplaying)
                .setContentTitle(nameOnly)
                .setContentText(contentText)
                .setAutoCancel(false).setWhen(0).setContentIntent(aIntent)
                .addAction(toDisplay, text, pIntent)
                .addAction(R.drawable.ic_stop_white_36dp, context.getResources().getString(R.string.stop), sIntent)
                .setPriority(Notification.PRIORITY_MAX);

enter image description here

Upvotes: 1

Views: 674

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199825

You need to use a MediaStyle notification and use setShowActionsInCompactView() to set which actions you want to appear in the compact, unexpanded view as explained in the Best practices in media playback talk from I/O 2016.

Upvotes: 3

Related Questions