当使用Android 13及更高版本时,播放器(如ExoPlayer)使用PlayerNotificationManager可能会出现问题,通常表现为通知无法显示。解决方法是使用最新的ExoPlayer版本(2.15.1或更高版本),并将通知渠道设置为IMPORTANCE_LOW,如下所示:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager =
(NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(
NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(channel);
}
PlayerNotificationManager playerNotificationManager = new PlayerNotificationManager(
context,
NOTIFICATION_CHANNEL_ID,
NOTIFICATION_ID,
new DescriptionAdapter(),
new NotificationListenerAdapter());
上述代码将创建一个IMPORTANCE_LOW优先级的通知渠道,并使用该渠道ID在PlayerNotificationManager中进行设置,从而避免了在Android 13上出现通知显示问题的问题。