Android disable notification sounds

Viewed 9646

I want to create a notification without any sounds. How can I do this? I tried the code below but it's not working for me:

notification = mBuilder
        .setStyle(notiStyle)
        .setSmallIcon(notificationIcon)
        .setTicker(title)
        .setWhen(0)
        .setAutoCancel(true)
        .setContentTitle(title)
        .setContentIntent(resultPendingIntent)
        .setSound(null).build();
3 Answers

In Android 26+ (Oreo) you do this by setting notification channel importance level to 'IMPORTANCE_LOW' or below.

val importance = NotificationManager.IMPORTANCE_LOW
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
    description = descriptionText
}
Related