【问题标题】:Display image from firebase as large image in push notification在推送通知中将来自 Firebase 的图像显示为大图像
【发布时间】:2021-05-22 13:53:58
【问题描述】:

我正在尝试将来自 Firebase 的图像显示为推送通知中的图像。但是,每当我尝试使用以下代码显示这一点时,我都会遇到异常

private void getBitmapAsyncAndDoWork(String imageUrl) {
    final Bitmap[] bitmap = {null};

    Glide.with(getApplicationContext())
            .asBitmap()
            .load(imageUrl)
            .addListener(new RequestListener<Bitmap>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                    return false;
                }
            })
            .into(new CustomTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

                    bitmap[0] = resource;
                    // TODO Do some work: pass this bitmap
                }

                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
            });
}

以下是异常详情

图像路径或访问没有问题,因为我可以使用下面的代码在另一个活动上显示相同的图像而没有任何问题

private void DisplayImage () {
    FirebaseStorage storage = mFirebaseService.getFirebaseStorageInstance();

    getBitmapAsyncAndDoWork(mSpelling.getImagePath());
    // Reference to an image file in Cloud Storage
    StorageReference storageReference = storage.getReferenceFromUrl(mSpelling.getImagePath());

    // ImageView in your Activity
    ImageView imageView = findViewById(R.id.imageView);

    Glide.with(this).load(storageReference).into(imageView);
}

有人可以确认我是否以正确的方式编码以在通知中显示 Firebase 图像?还有其他方法可以显示图像吗?

【问题讨论】:

  • 第二个 sn-p 似乎使用 FirebaseUI 通过 SDK 加载数据,而第一个 sn-p 通过下载 URL 加载数据。两种访问方式完全不同。如果你登录imageUrl,它会显示什么值?
  • @FrankvanPuffelen 两种方法都不同。但是,我添加它是为了展示在另一个活动中可以看到相同的图像,因此 URL 或访问没有问题。 URL 类似于 gs://.appspot.com/abc.PNG。
  • @FrankvanPuffelen .. 这两种方法都试图仅通过 Glide 加载图像。第一个直接参考图像。由于通知要求将其转换为 BMP,因此我使用 Glide 提供的不同方式
  • A gs://&lt;appname&gt;.appspot.com/abc.PNG URL 只能通过 FirebaseUI 加载,我不认为您的第一个代码 sn-p 正在使用它。
  • @FrankvanPuffelen 这解决了我的问题。谢谢

标签: android firebase push-notification firebase-storage android-glide


【解决方案1】:

看起来您的第一个 sn-p 正在尝试通过 Glide 自己加载图像,而第二个 sn-p 似乎是 using FirebaseUI to load and display the image

从 cmets 我们还可以看到,您在第一个 sn-p 中传递了一个 gs:// URL,Glide 无法识别该 URL,因为它没有对 gs:// 协议的内置支持。

因此,您要么必须在第一个 sn-p 中使用相同的 FirebaseUI 方法,要么可以使用 generate a download URL,这是 Glide 内置支持的 https:// URL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多