Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] kotlin – Android 10: No custom sound in notification

Posted on November 11, 2022 By

Solution 1 :

I found the problem.

Once you create a notification channel, you can’t change the sound of it.

So you have two solutions:

  • Uninstall the app and install again
  • Or change the notification channel id to create a new one with the right configuration.

Hope this help.

Solution 2 :

I solved the issue by uninstalling the app and reinstalling it

 private fun sendNotification(remoteMessage: RemoteMessage) {

    val fullScreenIntent = Intent(this, IncomingActivity::class.java).apply {
        flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
        putExtra(Constants.ROOM_ID, remoteMessage.data[Constants.ROOM_ID])
        putExtra(Constants.REMOTE_MSG_INVITER_TOKEN, remoteMessage.data[Constants.REMOTE_MSG_INVITER_TOKEN])
    }
    val fullScreenPendingIntent: PendingIntent? = TaskStackBuilder.create(this).run {
        // Add the intent, which inflates the back stack
        addNextIntentWithParentStack(fullScreenIntent)
        // Get the PendingIntent containing the entire back stack
        getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
    }
    val audioAttributes = AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
            .build()
    val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val notificationChannel = NotificationChannel(resources.getString(R.string.app_name), "Incoming call...", NotificationManager.IMPORTANCE_HIGH)
        notificationChannel.description = "Someone is calling you..."
        notificationChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, audioAttributes)
        notificationManager.createNotificationChannel(notificationChannel)
    }

    val notificationBuilder =
            NotificationCompat.Builder(this, resources.getString(R.string.app_name))
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle("Incoming call")
                    .setContentText("Someone is calling you...")
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setAutoCancel(true)
                    .setSound(Settings.System.DEFAULT_RINGTONE_URI)
                    .setChannelId(resources.getString(R.string.app_name))
                    .setContentIntent(fullScreenPendingIntent)
                    .setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.icon))

    val incomingCallNotification = notificationBuilder.build()
    notificationManager.notify(0, incomingCallNotification)

}

Problem :

I’m creating a channel with custom sound. The notifications are correctly displayed but the sound played is still the default one.

Creation of the channel


val audioAttribute = AudioAttributes.Builder()
  .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
  .setUsage(AudioAttributes.USAGE_NOTIFICATION)
  .build()


val sound = Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
  .authority(packageName)
  .path(R.raw.notifsound.toString()).build()


alertChannel.apply {
    enableVibration(true)
    description = "Signal alert channel"
    lockscreenVisibility = Notification.VISIBILITY_PUBLIC
    setSound(sound, audioAttribute)
}

notificationManager.createNotificationChannels(listOf(locationNotificationChannel,gpsStatusChannel,alertChannel))

I checked the URI with this

(contentResolver as ContentResolver).openInputStream(sound)

And it can read the file.

Comments

Comment posted by Bruno Coelho

I have exactly the same problem :/

Comment posted by Mike

Hi, The channel is created after the setting the sound. The sound is correctly defined, in the channel settings on the phone, I can read sound provided by the app.

READ  [FIXED] How to create UseCase for MVVM Clean architecture in android
Powered by Inline Related Posts
Android Tags:android, android-notifications, kotlin, notifications

Post navigation

Previous Post: [FIXED] java – The Android LoaderManager is deprecated. Now what?
Next Post: [FIXED] android – Is WorkManager the right solution for me?

Related Posts

[FIXED] java – Finding Percentage of color in image OpenCV Android SDK Android
[FIXED] raspberry pi – Android Things console not allowing me to create a build Android
[FIXED] java – Fragment not showing in home activity Android
[FIXED] java – How to return after get value from foreach in kotlin Android
[FIXED] android – how to update nodes inside other nodes in firebase Android
[FIXED] android – how to cumulate contextMenu and drag&drop? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme