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