Firebase通知中的图片

时间:2019-04-18 04:25:35

标签: android firebase-cloud-messaging

在通知中实施大图像时,由于图像未始终加载,因此我遇到了问题。当我逐行调试服务代码时,它的工作正常。

我的通知代码:

if (bitmap != null) {
            notificationBuilder
                    .setLargeIcon(bitmap)
                    .setStyle(new NotificationCompat.BigPictureStyle()
                            .setBigContentTitle(title)
                            .setSummaryText(message)
                            .bigPicture(bitmap)
                            .bigLargeIcon(null));
        }

URL代码中的位图:

try {
                    URL url = new URL(imageUrl);

                    InputStream input;
                    if (imageUrl.contains("https")) {
                        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
                        connection.setDoInput(true);
                        connection.connect();
                        input = connection.getInputStream();
                    } else {
                        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                        connection.setDoInput(true);
                        connection.connect();
                        input = connection.getInputStream();
                    }
                    Bitmap bitmap = BitmapFactory.decodeStream(input);
                    sendNotification(remoteMessage, bitmap);

                } catch (Exception e) {
                    e.printStackTrace();
                    sendNotification(remoteMessage, null);
                }

似乎

  

MyFirebaseMessagingService

正在完成/未正确执行getBitmapFromUrl()方法。有什么主意吗?

0 个答案:

没有答案