Android - collapse notification actions by default

Viewed 796

I have a notification that contains an action like this:

enter image description here

The action is always shown, I'd like to hide it by default so the user has to press the button at the top right to show the action so that the notification occupies less space.

I've read about using a low notification priority by calling setPriority on the NotificationCompat.Builder before posting the ongoing notification from my foreground service, but this doesn't seem to work. I'm using Android SDK version 28.

1 Answers

Starting from API 26, using PRIORITY_LOW is deprecated, instead you can use IMPORTANCE_LOW when you create the channel

NotificationChannel channel = new NotificationChannel(CHANNEL_ID, 
                                  CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);

Also keep the low priority in the NotificationCompat.Builder with builder.setPriority(NotificationCompat.PRIORITY_LOW)

Related