Expandable Notification(ํ์ฅํ ์๋ฆผ)
Large image notification(ํฐ ์ด๋ฏธ์ง ์ถ๊ฐ ์๋ฆผ)
Large block of text notification (ํฐ ํ
์คํธ ๋ธ๋ก ์๋ฆผ)
Inbox-style notification(๋ฐ์ํธ์งํจ ์คํ์ผ ์๋ฆผ)
Conversation in a notification(๋ํ ํ์ ์๋ฆผ)
Media controls notification(๋ฏธ๋์ด ์ปจํธ๋กค ์๋ฆผ)
private fun createNotification (
context : Context ,
track : Track ,
): Notification {
val pendingIntent = PendingIntent .getActivity(
context,
0 ,
Intent (context, PlayerActivity ::class .java).apply {
putExtra(PlayerActivity .KEY_PLAYER_TRACK , track)
putExtra(PlayerActivity .KEY_BOTTOM_PLAYER_CLICK , true )
},
PendingIntent .FLAG_UPDATE_CURRENT
)
val pausePendingInt =
PendingIntent .getService(
context, 0 ,
Intent (context, PlayerService ::class .java)
0 ,
)
val stopPendingIntent =
PendingIntent .getService(
context, 0 ,
Intent (context, PlayerService ::class .java).apply {
this .action = PlayerAction .STOP .value
},
0 ,
)
val stopAction = NotificationCompat .Action (
R .drawable.ic_close_white,
" " ,
stopPendingIntent,
)
val appName = context.getString(R .string.app_name)
val mediaSession = MediaSessionCompat (context, appName).apply {
setMetadata(
MediaMetadataCompat .Builder ()
.putString(MediaMetadata .METADATA_KEY_TITLE , track.title)
.putString(MediaMetadata .METADATA_KEY_ARTIST , track.desc)
.build()
)
}
return NotificationCompat .Builder (context, CHANNEL_ID )
.setSmallIcon(R .drawable.ic_launcher_background)
.setVisibility(NotificationCompat .VISIBILITY_PUBLIC )
.addAction(NotificationCompat .Action (
R .drawable.ic_pause_white,
" " ,
pausePendingInt,
))
.addAction(stopAction)
.setStyle(
androidx.media.app.NotificationCompat .MediaStyle ()
.setShowActionsInCompactView(0 , 1 )
.setMediaSession(mediaSession.sessionToken)
)
.setOngoing(true )
.setContentTitle(context.getString(R .string.app_name))
.setTicker(appName)
.setContentIntent(pendingIntent)
.build()
}
setOngoing(boolean ongoing) : ์๋ฆผ ๋ฆฌ์คํธ์์ ์ฌ์ฉ์๊ฐ ๊ทธ๊ฒ์ ํด๋ฆญํ๊ฑฐ๋ ์ข์ฐ๋ก ๋๋๊ทธํด๋ ์ฌ๋ผ์ง์ง ์์ ์ค์
setTicker(CharSequence text) : ์๋ฆผ์ด ์ํ ๋ฐ์ ๋ฐ ๋ ๊ทธ ๊ณณ์ ๋ํ๋๋ ํ
์คํธ
setStyle(NotificationCompat.Style style) : ์๋ฆผ ์คํ์ผ ์ ์ฉ(MediaStyle, InboxStyle, BigTextStyle, BigPictureStyle, MessagingStyle, Etc..)
setVisibility(int visibility) SystemUI๊ฐ ์ ๋ขฐํ ์์๋ ์ํฉ (์ฆ, ๋ณด์ ์ ๊ธ ํ๋ฉด์์)์์ ์๋ฆผ์ ์กด์ฌ์ ๋ด์ฉ์ ํ์ํ๋ ๋ฐฉ๋ฒ๊ณผ์๊ธฐ์ ์ํฅ์์ฃผ๋์ด ์๋ฆผ์ ๊ฐ์์ฑ ๋ฒ์ ์ค์