gpt4 book ai didi

android - 在紧凑 View 中显示按钮的 MediaStyle 通知

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:24 43 4
gpt4 key购买 nike

我将 MediaStyle 用于我的推送通知,以便我可以显示当前正在播放的歌曲元数据以及包含一个暂停按钮。我看到的问题是我的通知不会自动扩展以显示暂停按钮,即使我已经包含了 setShowActionsInCompactView()。如果我在锁定屏幕上下拉我的通知,它会展开并显示暂停按钮。但我希望它在不展开的情况下显示按钮。

通知显示方式的屏幕截图: http://cl.ly/image/3E2D0m403v1b

下拉通知展开后的显示截图: http://cl.ly/image/1N1i0G121i2Y

下面是我用来生成通知的代码 fragment :

        PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Intent intent = new Intent(BROADCAST_PLAYER_STOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(getResources().getString(R.string.app_name))
.setTicker(tickerString)
.setContentText(contentString)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(icon)
.addAction(R.drawable.ic_media_pause, "", pendingIntent)
.setContentIntent(pi)
.setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0)
.setMediaSession(mSession.getSessionToken()))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setWhen(0)
.setOngoing(true);
startForeground(NOTIFICATION_ID, notification.build());

最佳答案

要使用 NotificationCompat.MediaStyle,您必须使用 android.support.v7.app.NotificationCompat.Builder - 默认的 v4 Builder 不处理 v7 MediaStyle

关于android - 在紧凑 View 中显示按钮的 MediaStyle 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33810667/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com