Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - collapse notification actions by default

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.

like image 534
0ne_Up Avatar asked Oct 19 '25 04:10

0ne_Up


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)

like image 103
Zain Avatar answered Oct 22 '25 03:10

Zain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!