Android API 29 not playing notification sound

Viewed 353

I have the same problem as here and here except none of the answers worked for me.

I'm using a Pixel 3XL API 29 emulator. The notification pops up, but there is no sound. I tested it with

RingtoneManager.getRingtone(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).play()

in activity onCreate which plays fine. So sound works, just not notification sound.

Creating the channel:

private fun createTimerFinishedChannel(context: Context) {
    val name = context.getString(R.string.timer_finished_channel_name)
    val importance = NotificationManagerCompat.IMPORTANCE_HIGH
    val uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
    val audioAttributes =
        AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
            .build()
    val channel = NotificationChannel(CHANNEL_TIMER_FINISHED_ID, name, importance).apply {
        description = context.getString(R.string.timer_finished_channel_description)
        lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
        enableVibration(true)
        setSound(uri, audioAttributes)
    }
    NotificationManagerCompat.from(context).apply {
        createNotificationChannel(channel)
    }
}

Building the notification:

private fun createTimerFinishedNotificationBuilder(): NotificationCompat.Builder {
    val fullscreenIntent = Intent(this, MainActivity::class.java).let {
        it.action = ACTION_FINISHED_NOTIFICATION
        PendingIntent.getActivity(
            this, FULLSCREEN_INTENT_REQUEST_CODE, it, PendingIntent.FLAG_UPDATE_CURRENT)
    }
    return NotificationCompat.Builder(this, CHANNEL_TIMER_FINISHED_ID)
        .setSmallIcon(R.drawable.ic_tomato_24)
        .setContentTitle(getString(R.string.timer_notification_title))
        .setContentText(getString(R.string.timer_finished_text))
        .setContentIntent(createNotificationContentIntent())
        .setCategory(NotificationCompat.CATEGORY_ALARM)
        .setFullScreenIntent(fullscreenIntent, false)
        .setAutoCancel(true)
}

Other coding changes I tried:

  • setDefaults(NotificationCompat.DEFAULT_SOUND or NotificationCompat.DEFAULT_VIBRATE)
  • NotificationCompat.Builder#setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
  • setOnlyAlertOnce(true)
  • RingtoneManager.TYPE_NOTIFICATION
  • AudioAttributes.USAGE_ALARM
  • All the different AudioAttributes content types, including removing it

I checked the ring volume, and it is on.

The accepted answer on the other question says to complete the set up, but I don't see the notification for the set up in the status bar. Apparently, it's supposed to look like this:

set up wizard

I also checked the phone settings for somewhere to set up, but I didn't see anything.

Is there another reason notification sounds wouldn't work?

1 Answers

Try uninstalling the app totally, then install the app a fresh. Forgot the thread where this worked but it did for me.

Related