Android MediaStyle NotificationCompat displays 3 actions maximum

前提是你 提交于 2019-12-13 06:47:21

问题


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})
            );

回答1:


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.




回答2:


Eugen, please find the first action (the others are similar) :

   previousPI = PendingIntent.getBroadcast(context, 100, new Intent(TOOLS_CONST.ACTION_PREVIOUS), 0);

   previousAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_previous_light, null, previousPI).build();


来源:https://stackoverflow.com/questions/36100245/android-mediastyle-notificationcompat-displays-3-actions-maximum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!