if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val existingChannel = notificationManager.getNotificationChannel(id)
if (existingChannel != null) {
notificationManager.deleteNotificationChannel(id)
}
val channel = NotificationChannel(id, name, importance)
channel.description = description
channel.enableLights(true)
channel.setShowBadge(true)
channel.setBypassDnd(dnd)
channel.lockscreenVisibility = Notification.VISIBILITY_PRIVATE
channel.lightColor = R.color.cornflower_blue_dark
channel.enableVibration(true)
channel.setSound(path,
AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
.build()
)
notificationManager?.createNotificationChannel(channel)
}
我想在Android中播放自定义声音通知。我已经在通知频道中提到了这一点。但是setSound无法正常工作。 当应用程序在后台运行时,它将不会调用onMessageReceived()。 而且channel.setSound()也不起作用。 我想使用App提供的声音进行通知。