在我的应用程序中,我成功创建了一个通知,但播放的声音是我不想要的默认声音。我在 resources/raw/basic_notification.mp3 中有一个声音剪辑,我想在构建通知时播放它。
fun createContactMessageNotification(intent: PendingIntent?, title: String?, content: String): Notification {
return NotificationCompat.Builder(Application.instance, NautilusParams.NOTIFICATION_CHANNEL).apply {
setSmallIcon(R.drawable.ic_person_white_24dp)
setContentIntent(intent)
setContentTitle(title)
setContentText(content)
setAutoCancel(true)
setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+ =Application.instance.packageName + "/"+ R.raw.basic_notification))
setVibrate(longArrayOf(0, 150, 200, 150, 200, 150))
priority = NotificationCompat.PRIORITY_MAX
setCategory(NotificationCompat.CATEGORY_MESSAGE)
}.build()
}
我称之为
val notification = NotificationBuilder.createContactMessageNotification(resultPendingIntent,
message.fromaccountfirstname,
MessageUtils.getNotificationBodyByNewMessageType(message))
NotificationManagerCompat.from(Application.instance).notify(message.fromaccountid, notification)
但是,这不起作用。我还尝试使用 AudioAttributes 将其添加到通知通道构建器中,但仍然如此。我只打开了默认值。我怎样才能克服这个..?