首页 > 解决方案 > 通知 BigPictureStyle 在 6.0 之前和之后的设备上扩展

问题描述

我阅读了很多关于此的主题,但没有找到任何解决方案。我正在使用 FMC 通知并使用以下方法显示它们:

    public static void sendNotification(Context context, int id, String title, String bitmapUrl) {

    Bitmap bitmap = getBitmapfromUrl(bitmapUrl);

    Intent intent = new Intent(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    intent.putExtra("id", id);
    intent.putExtra("title", title);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, Constants.REQUEST_CODE_POST_DETAIL, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String channelId = context.getString(R.string.default_notification_channel_id);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(context, channelId)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(title)
                    .setContentText(context.getResources().getString(R.string.app_name))
                    .setStyle(
                            new NotificationCompat
                                    .BigPictureStyle()
                                    .bigPicture(bitmap)
                                    .bigLargeIcon(bitmap)
                                    .setBigContentTitle(title)

                    )
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)

                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(id, notificationBuilder.build());
}

我阅读了很多关于此的主题,但没有找到任何解决方案。

我已经读过只有堆栈顶部的通知应该显示为展开。在 6.0 之前的设备中,确切地说是 5.0.2 的华为,这总是很有效,第一个通知显示已经展开。在 6.0 之后的设备中,确切地说是 6.0.1 的华为,我的应用程序的 nofitiche 始终显示为折叠状态,并且只有向下滑动通知时它才会展开。

我尝试了其他代码示例,阅读了 android 文档,但没有解决问题。我还使用自定义通知来扩展单独的布局 xml,但它们在两个 android 版本中具有不同的行为并显示相同的问题。

我不明白为什么其他应用程序(例如 youtube)显示正确扩展的通知,所以这意味着方式是......

谁能澄清是否有办法至少显示第一个扩展通知,该通知至少适用于 5.0 及更高版本的所有版本?谢谢

标签: androidnotifications

解决方案


推荐阅读