当前位置:   article > 正文

android自定义通知声音无效,Android通知Notification设置setSound无效解决办法

andorid开发vivo手机设置通知栏提示音失败

2c48d2128e6b

u=1678011113,2635959946&fm=26&gp=0.jpg

对于大于等于API 26 [Build.VERSION.SDK_INT >= Build.VERSION_CODES.O],您需要在通知通道上设置声音

fun createNotifyChannel(context: Context): String? {

val sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.packageName + "/raw/" + R.raw.sound)

// NotificationChannels are required for Notifications on O (API 26) and above.

return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

val audioAttributes = AudioAttributes.Builder()

.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)

.setUsage(AudioAttributes.USAGE_NOTIFICATION)

.build()

// Initializes NotificationChannel.

val notificationChannel = NotificationChannel

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/575646
推荐阅读
相关标签
  

闽ICP备14008679号