When I create a MediaStyle notification, it exposes a button to choose media routing, like this one: see screenshot.
How do I get rid of this button? Or at least, how can I restrict playback to only local device (phone speaker)?
Here's how I create the notification:
MediaSessionCompat mediaSessionCompat = new MediaSessionCompat
(this, TAG, mComponent, mediaButtonReceiverPendingIntent);
mediaSessionCompat.setMetadata
(new MediaMetadataCompat.Builder()
.putString(MediaMetadata.METADATA_KEY_TITLE, title)
.putString(MediaMetadata.METADATA_KEY_ALBUM, album)
.build()
);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder
(this, CHANNEL_ID);
notificationBuilder
.setContentTitle(title)
.setStyle(new MediaStyle()
.setMediaSession(mediaSessionCompat.getSessionToken())
.setShowActionsInCompactView(0, 1, 2));
Okay, I think I found the solution. Here's the code:
And then use it like this: