再会,
我的项目中有以下代码来执行通知,因此通知工作正常,但我想添加以支持 android 8 的自定义声音不起作用......它只是使用手机的通知声音。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Uri mysound = null;
if(sound.equalsIgnoreCase("visitor_long"))
{
mysound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + File.pathSeparator + File.separator + getPackageName()+ "/res" + "/raw/" + sound + ".wav");
}
else{
mysound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + this.getPackageName() + "/raw/" + sound);
}
AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, contentTitle, NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel.
mChannel.setDescription(message);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mChannel.setSound(mysound, attributes); // This is IMPORTANT
if (notificationManager != null)
notificationManager.createNotificationChannel(mChannel);
}
if(notificationManager != null ) {
if(message != null) {
int messageHash = message.hashCode();
notificationManager.notify(messageHash, notificationBuilder.build());
}
}
我使用了以下链接,但它不起作用: