I would like to make an Android shutdown notification using MediaSession, which has several buttons on one page and some other buttons on another page. It will look like a notification to the Google Play Now App about android wear. I followed this github tutorial at https://github.com/PaulTR/AndroidDemoProjects/blob/master/MediaSessionwithMediaStyleNotification/app/src/main/java/com/ptrprograms/mediasessionwithmediastylenotification/MediaPlayerService.
However, each action has been added to a separate page dedicated to android wear. I want to group some of them on one page. For example, play / pause, pre and next on one page and a speed button on the second page. I would like to know if this can be achieved with a custom notification without using MediaSession in order to span an API of less than 21.
Thanks!
private void buildNotification( Notification.Action action ) { Notification.MediaStyle style = new Notification.MediaStyle(); Intent intent = new Intent( getApplicationContext(), MediaPlayerService.class ); intent.setAction( ACTION_STOP ); PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0); Notification.Builder builder = new Notification.Builder( this ) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle( "Media Title" ) .setContentText( "Media Artist" ) .setDeleteIntent( pendingIntent ) .setStyle(style); builder.addAction( generateAction( android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS ) ); builder.addAction( generateAction( android.R.drawable.ic_media_rew, "Rewind", ACTION_REWIND ) ); builder.addAction( action ); builder.addAction( generateAction( android.R.drawable.ic_media_ff, "Fast Foward", ACTION_FAST_FORWARD ) ); builder.addAction( generateAction( android.R.drawable.ic_media_next, "Next", ACTION_NEXT ) ); style.setShowActionsInCompactView(0,1,2,3,4); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificationManager.notify( 1, builder.build() ); }
UPDATED CODE: setMediaSession gives this compilation error when I pass a token to it: the setMediaSession (MediaSessionCompat.Token) method of type NotificationCompat.MediaStyle is not applicable for arguments (MediaSession.Token). 3 actions are still displayed on three separate pages for android wear.
private void buildNotification( Notification.Action action ) { NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle(); //style.setMediaSession(mSession.getSessionToken()); style.setMediaSession(null); style.setShowActionsInCompactView(1,2); Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.drawable.pinkfloyd); NotificationCompat.Builder builder = new NotificationCompat.Builder( this ); builder.setSmallIcon(R.drawable.ic_launcher); builder.setLargeIcon(icon); builder.setContentTitle( "Media Title" ); builder.setContentText( "Media Artist" ); builder.setColor(Color.argb(0, 60, 13, 77)); builder.setStyle(style); builder.addAction(R.drawable.ic_launcher, "Test1 ", null); builder.addAction(R.drawable.ic_launcher, "Test2 ", null); builder.addAction(R.drawable.ic_launcher, "Test3 ", null); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificationManager.notify( 1, builder.build() ); }