问题?好吧,我正在尝试制作我的MediaStyle通知,并给它一个MediaSession令牌.我的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,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令牌与Notification MediaStyle.setMediaSession全部内容,希望文章能够帮你解决android – 无法使用支持v4 MediaSession令牌与Notification MediaStyle.setMediaSession所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)