出现这个问题的原因是Android 13中Notification的默认行为发生了改变。假设您使用了以下代码来创建BigPicture通知:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap)
.bigLargeIcon(null));
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationID, builder.build());
那么您可能会发现在Android 13设备上通知并没有显示所期望的大图片。
要解决这个问题,您需要通过设置Notification的messagingStyle参数来手动启用大图片样式。以下是一个示例代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setStyle(new NotificationCompat.MessagingStyle(""))
.setLargeIcon(bitmap)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap)
.bigLargeIcon(null));
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationID, builder.build());
请注意,在这个示例代码中,我们使用了MessagingStyle参数并将其设置为空字符串。大图片样式设置在这之后,这将启用Android 13中的新通知样式。
通过更新您的代码并使用上述示例,您就可以在Android 13设备中正确地显示大图片通知。