在推送通知中将来自 firebase 的图像显示为大图像
Display image from firebase as large image in push notification
我正在尝试将来自 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) {
}
});
}
异常详情如下
图像路径或访问没有问题,因为我可以在另一个 activity 上显示相同的图像而没有任何问题使用下面的代码
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 图像吗?还有其他显示图像的方法吗?
您的第一个代码片段似乎试图通过 Glide 自行加载图像,而第二个代码片段似乎是 using FirebaseUI to load and display the image。
从评论中我们还可以看到您在第一个代码段中传递了 gs://
URL,Glide 无法识别它,因为它没有对 gs://
协议。
因此您要么必须在第一个代码段中使用相同的 FirebaseUI 方法,要么您可以 generate a download URL 这是 Glide 内置的 https://
URL-支持。
我正在尝试将来自 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) {
}
});
}
异常详情如下
图像路径或访问没有问题,因为我可以在另一个 activity 上显示相同的图像而没有任何问题使用下面的代码
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 图像吗?还有其他显示图像的方法吗?
您的第一个代码片段似乎试图通过 Glide 自行加载图像,而第二个代码片段似乎是 using FirebaseUI to load and display the image。
从评论中我们还可以看到您在第一个代码段中传递了 gs://
URL,Glide 无法识别它,因为它没有对 gs://
协议。
因此您要么必须在第一个代码段中使用相同的 FirebaseUI 方法,要么您可以 generate a download URL 这是 Glide 内置的 https://
URL-支持。