Android MediaStyle NotificationCompat最多显示3个操作 [英] Android MediaStyle NotificationCompat displays 3 actions maximum

查看:334
本文介绍了Android MediaStyle NotificationCompat最多显示3个操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将NotificationCompat.Builder设置为MediaStyle时遇到2个问题:

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

1)我设置了5个动作,展开的通知中仅显示3个。 (显示的前3个动作正常。)

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

2)尽管我设置了1个动作,但紧凑型通知中没有显示任何动作。

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

我正在Lollipop 5.1.1(Cyanogen)上的Samsung S4上进行测试,我的应用程序使用支持库23.2.1

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

下面是我的NotificationCompat.Builder:

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


推荐答案

我已经找到了此问题的原因。我使用的是v4 appcompatpat支持库,而不是v7

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

因此替换:

import android.support.v4.app.NotificationCompat;

作者:

import android.support.v7.app.NotificationCompat;

解决了问题。

是我的问题中另一个带有媒体样式通知的原因。

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

这篇关于Android MediaStyle NotificationCompat最多显示3个操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆