티스토리 뷰

android

push notification set custom sound (.mp3)

boywin1992 2022. 7. 11. 14:10
728x90

val soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + applicationContext.packageName + "/" + R.raw.d39push1)

 

val notificationBuilder = NotificationCompat.Builder(this, channelId)

 .setSound(soundUri)

 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

 val importance = NotificationManager.IMPORTANCE_DEFAULT

 val notificationChannel = NotificationChannel(channelId, "Notice", importance)
 val audioAttributes = AudioAttributes.Builder()
  .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
  .setUsage(AudioAttributes.USAGE_NOTIFICATION)
  .build()
 notificationChannel.setSound(soundUri, audioAttributes)
 notificationManager.createNotificationChannel(notificationChannel)

}

728x90

'android' 카테고리의 다른 글

안드로이드 화면 방향 고정하는 방법  (0) 2022.07.28
app icon 을 변경해 봅시다  (0) 2022.07.21
wireless debugging (android 11 or less)  (0) 2022.05.28
constraint dimension ratio  (0) 2022.05.28
how to make ... at view  (0) 2022.05.24
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함