当前,我们的应用程序正在尝试利用通知通道来管理我们应用程序中的所有通知。这是我们的代码段:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
NotificationChannel channel = new NotificationChannel("one channel", "one channel", NotificationManager.IMPORTANCE_LOW);
channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel);
channel = new NotificationChannel("two channel", "two channel", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
channel = new NotificationChannel("three channel", "three channel", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
channel = new NotificationChannel("four channel", "four channel", NotificationManager.IMPORTANCE_HIGH);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
channel.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.four_channel_sound), audioAttributes);
channel.setVibrationPattern({300L, 500L});
notificationManager.createNotificationChannel(channel);
一切正常,直到用户拨打电话为止。此时,带有“四通道”通知的通知将仅在通知工具栏中显示图标,而不会发出应有的典型声音或振动。它甚至不会偷看。我知道这一点:
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
将解决声音问题,但我想检查是否有人知道这是通知通道存在问题的原因。
非常感谢大家!