I am working on some Android code and I do not want to create a MediaStyle alert. I already use AppCompat for most media players and mediasession, and what I do not use yet, I plan to switch so that I can maintain 4.x compatibility.
Question? Well, I'm trying to make my MediaStyle notification and give it a MediaSession token. My support .v4.media.session.MediaSession.Token does not seem to be compatible with media.session.MediaSession.Token
I tried casting and just left it raw. I'm honestly confused because the docs say they are compatible.
If you want to leave the rest of the code, you can find it here.
Or you can see the corresponding code 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());
ms.setActive(true);
ms.setCallback(new MediaSessionCompat.Callback() {
});
ms.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
final Notification noti = new Notification.Builder(this)
.setShowWhen(false)
.setStyle(new Notification.MediaStyle()
.setMediaSession(ms.getSessionToken())
.setShowActionsInCompactView(0, 1, 2))
.setColor(0xFFDB4437)
.setLargeIcon(artwork)
.setSmallIcon(R.drawable.your_small_icon)
.setContentText("Pink Floyd")
.setContentInfo("Dark Side of the Moon")
.setContentTitle("The Great Gig in the Sky")
.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();