- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在编写一些 Android 代码,我不想构建 MediaStyle 通知。我已经将 AppCompat 用于 m 媒体播放器和媒体 session 的大部分,而我还没有使用的部分我计划进行切换,以便保持 4.x 兼容性。
问题?好吧,我正在尝试制作我的 MediaStyle 通知,并给它一个 MediaSession token 。我的 support.v4.media.session.MediaSession.Token 似乎与 media.session.MediaSession.Token 不兼容
我已经尝试过类型转换,只是保持原始状态。老实说,我很困惑,因为文档说它们是兼容的。
如果你想要剩下的代码,code can be found here
或者你可以在这里查看相关代码。
Intent nIntent = new Intent(context, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, nIntent, 0);
n.setLatestEventInfo(context, notifTitle, notifMessage, pIntent);
notificationManager.notify(notifId, n);
ComponentName c = new ComponentName("com.thefan.android", "BackgroundService");
ms = new MediaSessionCompat(this, "TheFan", c, pIntent);
ms.setMetadata(new MediaMetadataCompat.Builder()
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, artwork)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "Pink Floyd")
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, "Dark Side of the Moon")
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, "The Great Gig in the Sky")
.build());
// Indicate you're ready to receive media commands
ms.setActive(true);
// Attach a new Callback to receive MediaSession updates
ms.setCallback(new MediaSessionCompat.Callback() {
// Implement your callbacks
});
// Indicate you want to receive transport controls via your Callback
ms.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
// Create a new Notification
final Notification noti = new Notification.Builder(this)
// Hide the timestamp
.setShowWhen(false)
// Set the Notification style
.setStyle(new Notification.MediaStyle()
// Attach our MediaSession token
.setMediaSession(ms.getSessionToken())
// Show our playback controls in the compat view
.setShowActionsInCompactView(0, 1, 2))
// Set the Notification color
.setColor(0xFFDB4437)
// Set the large and small icons
.setLargeIcon(artwork)
.setSmallIcon(R.drawable.your_small_icon)
// Set Notification content information
.setContentText("Pink Floyd")
.setContentInfo("Dark Side of the Moon")
.setContentTitle("The Great Gig in the Sky")
// Add some playback controls
.addAction(R.drawable.your_prev_icon, "prev", retreivePlaybackAction(3))
.addAction(R.drawable.your_pause_icon, "pause", retreivePlaybackAction(1))
.addAction(R.drawable.your_next_icon, "next", retreivePlaybackAction(2))
.build();
最佳答案
神奇。有一个 Token.getToken();
您需要使用它。
话又说回来,MediaStyle Notifications 只兼容 API 21,祝你好运。
关于android - 无法将支持 v4 MediaSession token 与 Notification MediaStyle.setMediaSession 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29701637/
我正在尝试在音频 Android 应用程序中使用 MediaStyle 通知,如 audio app documentation 中所述。以及 media style documentation .我
我有一个简单的 Android 应用程序,其中包含一个 Activity和 Service源自 MediaBrowserServiceCompat .我已通过使用 MediaBrowserCompat
我在我的应用中使用了 MediaStyle 通知。它在 Android 11 之前一直运行良好。在 Android 11 上,它使 Android UI 崩溃(不仅是应用程序,它还破坏了 Androi
尝试构建一个实时流媒体播放应用程序,28 及以下 sdk 中的媒体样式通知在没有任何搜索栏的情况下看起来不错,但在 Android 10(SDK 29)中运行相同的应用程序时,通知显示了额外的搜索栏,
在我的应用程序中,我有一个媒体通知(使用 MediaStyle)并且我需要具有不同色调的操作图标。我想要实现的一个例子是在 Android N 上运行的 Spotify 通知: Spotify not
Lollipop 中新的 Android MediaStyle 通知没有关闭按钮。看起来 Google Code 上已经有一个错误。 在错误解决之前,有人知道什么是解决此问题的好方法吗? 我们应该延迟
我正在使用新的 Notification.MediaStyle 类向 FTP 流式音乐播放器应用程序实现 Lollipop 风格的通知。我将专辑封面设置为我的“大图标”。 鉴于专辑封面直接取自当前正在
我们正在将正在进行的播放通知迁移到 Lollipop 中引入的 MediaStyle 通知。 RemoteControlClient 似乎已被弃用,并且 MediaStyle 通知未处理媒体按钮事件(
使用 android.support.v7.app.NotificationCompat.MediaStyle 构建的非自定义通知在 Android Marshmallow 上可能会以非常低的对比度显
我的自定义媒体样式通知不再适用于我的音乐应用的 Android 11。它在 Android 10 和以前的版本中运行良好。 是否需要添加任何其他代码才能在 Android 11 中运行。 我应该补充一
我创建了一个扩展 MediaBrowserServiceCompat 的服务。该服务持有对我的播放器的引用,并创建一个带有回调的新 MediaSession。每次播放器更改状态时,我都会更新 Medi
我将 MediaStyle 用于我的推送通知,以便我可以显示当前正在播放的歌曲元数据以及包含一个暂停按钮。我看到的问题是我的通知不会自动扩展以显示暂停按钮,即使我已经包含了 setShowAction
我发现 MediaStyle setStyle 在我使用时不起作用NotificationCompat.builder(this) 发出通知。 我的意思是,当在 NotificationCompat.
当我尝试在运行 Android 5.0.1 的 HUAWEI P8 lite 设备上显示通知时,我的应用程序崩溃(它在 Nexus 和三星设备上运行良好)。我的大部分代码取自 Ian Lake 的视频
所以,我有一个 PlayerService,它基本上是一个音频播放器。它位于前台,并使用 MediaStyle 和自定义操作(通知中的按钮),如上一个、播放/暂停、下一个和关闭。 问题是,当我启动一些
我有一个应用程序可以从服务中复制网络广播(使用 AACDecoder 库)并在 Activity 未恢复时在简单的持续通知中显示正在播放的内容。我想要的是通过 NotificationCompat.M
只有上一个按钮在 android 的 NotificationCompat.MediaStyle() 中有效。为什么我的下一步和暂停按钮在 Android 通知中起作用。 private void s
我想使用新的 Android L MediaStyle 模板创建媒体播放通知。现在,我成功地完成了上一个、播放、暂停、下一个等操作(通过使用 addAction(),但我找不到像在Android No
android.support.v4.media.app.NotificationCompat.MediaStyle() 在音乐播放器应用程序中运行良好,但在迁移到 android x 后我收到此错误
我正在编写一些 Android 代码,我不想构建 MediaStyle 通知。我已经将 AppCompat 用于 m 媒体播放器和媒体 session 的大部分,而我还没有使用的部分我计划进行切换,以
我是一名优秀的程序员,十分优秀!