【问题标题】:Android API 29 not playing notification soundAndroid API 29 不播放通知声音
【发布时间】:2021-04-01 23:07:24
【问题描述】:

我和herehere 有同样的问题,但没有一个答案对我有用。

我使用的是 Pixel 3XL API 29 模拟器。通知弹出,但没有声音。我用

测试了它
RingtoneManager.getRingtone(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).play()

在活动 onCreate 中播放良好。所以声音有效,只是没有通知声音。

创建频道:

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

构建通知:

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

我尝试的其他编码更改:

  • setDefaults(NotificationCompat.DEFAULT_SOUND or NotificationCompat.DEFAULT_VIBRATE)
  • NotificationCompat.Builder#setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
  • setOnlyAlertOnce(true)
  • RingtoneManager.TYPE_NOTIFICATION
  • AudioAttributes.USAGE_ALARM
  • 所有不同的AudioAttributes 内容类型,包括删除它

我检查了铃声音量,它是开着的。

另一个问题的接受答案是完成设置,但我没有在状态栏中看到设置通知。显然,它应该是这样的:

我还检查了要设置的地方的手机设置,但我什么也没看到。

通知声音不起作用还有其他原因吗?

【问题讨论】:

    标签: android android-notifications


    【解决方案1】:

    尝试完全卸载该应用,然后重新安装该应用。忘记了这个工作的线程,但它对我有用。

    【讨论】:

      猜你喜欢
      • 2012-01-14
      • 2012-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多