The MediaStyle
class is a part of the Android Support Library v4 and is used to style a notification as a media notification, which is a type of notification that is used to display information about media playback.
To use the MediaStyle
class, you will first need to include the Android Support Library v4 in your project. You can do this by adding the following dependency to your build.gradle
file:
implementation 'com.android.support:support-v4:28.0.0'
Once you have included the library in your project, you can use the MediaStyle
class as follows:
import android.support.v4.media.app.NotificationCompat; import android.support.v4.media.app.NotificationCompat.MediaStyle; ... NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification) .setContentTitle("Title") .setContentText("Content text") .setStyle(new MediaStyle() .setShowActionsInCompactView(0, 1, 2) .setMediaSession(mediaSession.getSessionToken()));
In this example, we create a notification builder and set the style to a MediaStyle
object. We then use the setShowActionsInCompactView
method to specify which actions should be shown in the compact view of the notification and the setMediaSession
method to set the MediaSession
object that this notification belongs to.
For more information about media notifications and the MediaStyle
class, you can refer to the Android documentation.