Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show colored notification for media in Android Oreo?

enter image description here

As you already know that Android Oreo introduced the new design for media controls, rather than selecting a singular color for the notification based on the app's color, media playback notifications can instead draw colors out of the album artwork. Android then uses those colors to make a notification that blends the artwork into the notification while making the notification itself pop in your notification shade.

May I know how we can do this ?

like image 564
mob_web_dev Avatar asked Mar 20 '18 10:03

mob_web_dev


People also ask

How do I get notifications to show on Android photos?

To add an image in your notification, pass an instance of NotificationCompat. BigPictureStyle to setStyle() .


1 Answers

This is MediaStyle for Notification. You need to set MediaStyle and media session tokon and thats it. For example:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);

//building some actions...

builder.setSmallIcon(R.mipmap.ic_launcher)
                .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(0, 1, 2)
                        .setShowCancelButton(true)
                        .setMediaSession(mediaSessionCompat.getSessionToken()))
                .setCategory(NotificationCompat.CATEGORY_TRANSPORT)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setShowWhen(false)
                .setContentTitle("Title Name")
                .setContentText("Content text")
                .setSmallIcon(R.drawable.pause)
                .setWhen(0)
                .setAutoCancel(true)
                .setLargeIcon(icon);

You can find tutorial here: Tutorial

like image 200
Mateusz Kaflowski Avatar answered Oct 05 '22 00:10

Mateusz Kaflowski