3

In my application i successfully create a notification but the sound that plays is the default which i dont want. I have a sound clip in the resources/raw/basic_notification.mp3 and i want to play this when the notification is built.

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()
        }

and i call it like

val notification = NotificationBuilder.createContactMessageNotification(resultPendingIntent,
                                message.fromaccountfirstname,
                                MessageUtils.getNotificationBodyByNewMessageType(message))
                            NotificationManagerCompat.from(Application.instance).notify(message.fromaccountid, notification)

However this doesnt work. I also tried to add it in the Notification Channel builder with the AudioAttributes but still. I only got the default on. How can i overcome this..?

james04
  • 1,580
  • 2
  • 20
  • 46
  • Android notifications are notorious for having weird issues when altered after the channels have already been created. Try completely uninstalling and reinstalling the app to see if that resolves your issue. – PGMacDesign Oct 24 '19 at 21:48
  • However...should i put the setSound method in the notification channel setup..? – james04 Oct 24 '19 at 22:29

0 Answers0