在某些Android设备中获取空白通知

时间:2017-08-21 04:57:19

标签: android push-notification notifications

在某些设备中,我收到一个空白(白色)通知,如附加屏幕截图。在某些设备中,它运行良好。请帮我解决这个问题。  enter image description here

 Intent intent = new Intent(ctx, NotificationDetailActivity.class);
            intent.putExtra("id", id);
            PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent,
                    PendingIntent.FLAG_ONE_SHOT);
            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
            builder.setTicker(getResources().getString(R.string.app_name));
            // Sets the small icon for the ticker
            builder.setSmallIcon(getNotificationIcon());
            builder.setLargeIcon(result);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setContentTitle(title);
            builder.setContentText(messageBody);
            builder.setSound(defaultSoundUri);
            builder.setContentIntent(pendingIntent);
            builder.setAutoCancel(true);
            Notification notification = builder.build();
            RemoteViews expandedView =
                    new RemoteViews(ctx.getPackageName(), R.layout.custom_notification);
            if (Build.VERSION.SDK_INT >= 16)
            {
                // Inflate and set the layout for the expanded notification view
                expandedView.setImageViewBitmap(R.id.imgBigImage, result);
                notification.bigContentView = expandedView;
                NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                nm.notify(Integer.parseInt(id), notification);
            } else {
                NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(ctx)
                        .setSmallIcon(getNotificationIcon())
                        .setLargeIcon(result)
                        .setColor(getResources().getColor(R.color.colorPrimary))
                        .setContentTitle(title)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);
                NotificationManager notificationManager =
                        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(Integer.parseInt(id), notificationBuilder.build());
            }

1 个答案:

答案 0 :(得分:0)

尝试setBigContentViewNotificationCompat.Builder,检查一下是否有效: -

Intent intent = new Intent(ctx, NotificationDetailActivity.class);
    intent.putExtra("id", id);
    PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//        Notification notification = builder.build();
        RemoteViews expandedView =
                new RemoteViews(ctx.getPackageName(), R.layout.custom_notification);
        if (Build.VERSION.SDK_INT >= 16)
        {
            builder.setTicker(getResources().getString(R.string.app_name));
            // Sets the small icon for the ticker
            builder.setSmallIcon(getNotificationIcon());
            builder.setLargeIcon(result);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setContentTitle(title);
            builder.setContentText(messageBody);
            builder.setSound(defaultSoundUri);
            builder.setContentIntent(pendingIntent);
            builder.setAutoCancel(true);
            // Inflate and set the layout for the expanded notification view
            expandedView.setImageViewBitmap(R.id.imgBigImage, result);
//            notification.bigContentView = expandedView;
            builder.setCustomBigContentView(expandedView);
        } else {
            builder.setSmallIcon(getNotificationIcon());
            builder.setLargeIcon(result);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setContentTitle(title);
            builder.setContentText(messageBody);
            builder.setAutoCancel(true);
            builder.setSound(defaultSoundUri);
            builder.setContentIntent(pendingIntent);
        }
        nm.notify(Integer.parseInt(id), builder.build());