1

I have the following setup for a media style notification:

NotificationCompat.Builder nc = new NotificationCompat.Builder(this, CHANNEL_ID);
        NotificationManager nm = (NotificationManager) this.getSystemService( Context.NOTIFICATION_SERVICE );
        nc.setContentIntent(pendingIntent);
        nc.setSmallIcon(R.drawable.play);
        nc.setAutoCancel(true);
        nc.setCustomBigContentView(view);
        nc.setContentTitle("MusicPlayer");
        nc.setPriority(NotificationCompat.PRIORITY_MAX);
        nc.setContentText("Control AUdio");
        Notification notification = nc.build();
        notification.flags = NotificationCompat.FLAG_ONGOING_EVENT|NotificationCompat.FLAG_FOREGROUND_SERVICE
                | NotificationCompat.FLAG_NO_CLEAR;
        view.setOnClickPendingIntent(R.id.notif_play, playbackAction(0));
        view.setOnClickPendingIntent(R.id.notif_next, playbackAction(2));
        view.setOnClickPendingIntent(R.id.notif_previous, playbackAction(3));  

but, I don't know how to add a MediaSession to this. The only way I knew was:

.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                        // Attach our MediaSession token
                        .setMediaSession(mediaSession.getSessionToken())
                        // Show our playback controls in the compact notification view.
                        .setShowActionsInCompactView( 1, 2))  

but, this really messes up the RemoteView, how can I add a MediaSession while retaining the RemoteView

4

0 回答 0