Android 通知通道设置声音和振动不工作

Android 通知通道设置声音和振动不工作,android,kotlin,notification-channel,Android,Kotlin,Notification Channel,我有一个播放声音的问题,当通知到来时,通知正在显示,但没有声音或振动,我看到了许多关于如何将声音和振动设置到通知频道的问题和答案,但它不起作用,这就是我尝试的方式 val pattern = longArrayOf(0, 200, 60, 200) val chatSound = Uri.parse("${ContentResolver.SCHEME_ANDROID_RESOURCE}://" + context.packageName + "/" + R.raw.chat_alert) val

我有一个播放声音的问题,当通知到来时,通知正在显示,但没有声音或振动,我看到了许多关于如何将声音和振动设置到通知频道的问题和答案,但它不起作用,这就是我尝试的方式

val pattern = longArrayOf(0, 200, 60, 200)
val chatSound = Uri.parse("${ContentResolver.SCHEME_ANDROID_RESOURCE}://" + context.packageName + "/" + R.raw.chat_alert)
val mBuilder = NotificationCompat.Builder(context, CHANNEL_ID)
  .setSmallIcon(R.mipmap.ic_launcher)
  .setContentTitle(title)
  .setContentText(body)
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

val notification = mBuilder.build()

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
  val mChanel = NotificationChannel(CHANNEL_ID, "test", NotificationManager.IMPORTANCE_HIGH)
  val audioAttributes = AudioAttributes.Builder()
    .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
    .build()
  mChanel.setSound(chatSound, audioAttributes)
  mChanel.enableVibration(true)
  mChanel.enableLights(true)
  mChanel.vibrationPattern = pattern
  mNotificationManager.createNotificationChannel(mChanel)
}
mNotificationManager.notify(i, notification)
我正在测试安卓派

targetSdkVersion 28

似乎当第一次创建通知通道时,如果发生了更改,它不会自动更新,就像在我的案例中一样,起初,我在没有声音和振动的情况下运行通知通道


解决方案:清除应用程序数据或卸载应用程序,然后它就可以正常工作了

非常感谢。我花了大约半个小时在谷歌上找到这个答案