u2gilles u2gilles - 3 months ago 11
Android Question

Android MediaStyle NotificationCompat displays 3 actions maximum

I have 2 problems with my NotificationCompat.Builder set up as MediaStyle :

1) I set up 5 actions and only 3 are displayed in the expanded notification. (The first 3 displayed actions are working fine).

2) None action is displayed in the compact notification though I set up 1 action.

I'm testing on a Samsung S4 on Lollipop 5.1.1 (Cyanogen) and my app uses support library 23.2.1

Below is my NotificationCompat.Builder :

notificationBuilder = new NotificationCompat.Builder(act)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setCategory(NotificationCompat.CATEGORY_TRANSPORT)
.setContentTitle(podcastName)
.setContentText(episodeName)
.setOngoing(true)
.setShowWhen(true)
.setContentIntent(activityMainPI)
.setSmallIcon(smallIcon)
.setLargeIcon(largeIcon)
.setAutoCancel(false)
.addAction(previousAction)
.addAction(playAction)
.addAction(nextAction)
.addAction(rewindAction)
.addAction(forwardAction)
.setStyle(new MediaStyle()
.setShowActionsInCompactView(new int[]{1})
);

Answer

I have found the reason for this problem. I used the v4 appcompat support library instead of the v7

So replacing :

import android.support.v4.app.NotificationCompat;

by :

import android.support.v7.app.NotificationCompat;

fixed the problem.

This also was the reason of another of my issues with the media style notification.