我試圖顯示一個圖像從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) {
}
});
}
以下是例外情況的詳細信息
映像路徑或訪問沒有問題,因為我可以在另一個活動上顯示相同的映像,而使用下面的代碼不會出現(xiàn)任何問題
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加載圖像,而第二個代碼段似乎正在使用FirebaseUI加載和顯示圖像。
從注釋中我們還可以看到,您在第一個代碼片段中傳遞了一個
gs://
URL,Glide無法識別該URL,因為它不支持built-in協(xié)議。因此,您要么在第一個代碼片段中使用相同的FirebaseUI方法,要么生成一個下載URL,它是Glide支持的
https://
URL。