【发布时间】: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://<appname>.appspot.com/abc.PNGURL 只能通过 FirebaseUI 加载,我不认为您的第一个代码 sn-p 正在使用它。 -
@FrankvanPuffelen 这解决了我的问题。谢谢
标签: android firebase push-notification firebase-storage android-glide