收到通知时,它会播放声音,但不是我的自定义声音。这是设置频道声音的代码。我需要更改什么?
private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Uri ringtone = Uri.parse("android.resource://" + getApplicationContext().getPackageName()+"/" +R.raw.videocall);
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CustomFirebaseMessagingService.CHANNEL_ID, name, importance);
channel.setDescription(description);
AudioAttributes.Builder audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE);
channel.setSound(ringtone,audioAttributes.build());
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
Log.d(MainActivity.TAG, "Created notification channel");
}
}
答案 0 :(得分:1)
好的,我不需要更改代码。我认为Android以某种方式缓存了旧声音。为了解决这个问题,我只是在创建NotificationChannel时将频道ID更改为其他名称,因此Android不会使用缓存的声音文件。