Skip to content

Instantly share code, notes, and snippets.

@Arunshaik2001
Created November 21, 2022 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arunshaik2001/74eb33025884b17038640ac44f2b21ef to your computer and use it in GitHub Desktop.
Save Arunshaik2001/74eb33025884b17038640ac44f2b21ef to your computer and use it in GitHub Desktop.
fun createNotificationWithMediaControl(context: Context){
val icon = BitmapFactory.decodeResource(
context.resources,
R.drawable.aquarium
)
val mediaSession = MediaSessionCompat(context,"myTag")
val notification = NotificationCompat.Builder(context, NotificationChannels.CHANNEL1)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.desk)
.addAction(R.drawable.previous, "Previous", null)
.addAction(R.drawable.pause, "Pause", null)
.addAction(R.drawable.next, "Next", null)
.setStyle(androidx.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0,1,2)
.setMediaSession(mediaSession.sessionToken))
.setContentTitle("music_land")
.setContentText("Creative Awesome Band")
.setLargeIcon(icon)
.build()
with(NotificationManagerCompat.from(context)) {
notify(12544567, notification)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment