I'm trying to send an alarm like notification that stays on the screen and plays the alarm sound until it's closed.
I tried setting the alarm sound on the notification channel and on the notification itself but nothing seems to work, the notification always plays the default notification sound.
val name = "name"
val descriptionText = "desc"
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel("id", name, importance).apply {
description = descriptionText
}
val notificationManager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
val audioAttributes = AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build()
channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), audioAttributes)
val builder = NotificationCompat.Builder(context, "id")
.setSmallIcon(R.drawable.ic_android_black_24dp)
.setContentTitle("textTitle")
.setContentText("textContent")
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
.setPriority(NotificationCompat.PRIORITY_MAX)
//.setCategory(NotificationCompat.CATEGORY_ALARM)
.setFullScreenIntent(fullScreenPendingIntent, true)
.addAction(1, "a", closeButtonPendingIntent)
with(NotificationManagerCompat.from(context)) {
notify(0, builder.build())
}