//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);
}
修改成了其他铃声,发现不生效,我给他重启依然不生效,我试过卸载发现修改的铃声终于生效了,至于震动之前没震动,我卸载重装后 也生效了。