简书链接:android通知震动不生效问题
文章字数:107,阅读全文大约需要1分钟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| //Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.custom_sound); Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_NOTIFICATION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = createChannel(context, PUSH_CHANEL_ID, PUSH_CHANEL);//只需要创建一次。。 // 设置通道的声音 AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build();
channel.setSound(soundUri, audioAttributes); channel.enableVibration(true); channel.canShowBadge(); channel.enableLights(true); long[] vibrationPattern = {600, 100, 600, 100, 600, 100, 400, 100,100}; channel.setVibrationPattern(vibrationPattern); notificationManager.createNotificationChannel(channel); }
|
修改成了其他铃声,发现不生效,我给他重启依然不生效,我试过卸载发现修改的铃声终于生效了,至于震动之前没震动,我卸载重装后 也生效了。