2017-05-29 38 views
0

我能夠加載使用此代碼來回回火力地堡存儲圖片:的Android UI火力地堡圖像加載不工作

StorageReference storageRef = storage.getReference().child("Users/" +userId +".jpg"); 
final long ONE_MEGABYTE = 1024 * 1024; 
storageRef.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() { 
      @Override 
      public void onSuccess(byte[] bytes) { 
       Log.d(TAG, "downloadImageFromServer onSuccess: "); 
       Glide.with(UserActivity.this).load(bitmap).asBitmap().into((ImageView) findViewById(R.id.user_photo)); 
      } 
     }).addOnFailureListener(new OnFailureListener() { 
      @Override 
      public void onFailure(@NonNull Exception exception) { 
       Log.e(TAG, "downloadImageFromServer onFailure() called with: exception = [" + exception + "]"); 
      } 
     }); 

但不使用此代碼:

final StorageReference storageReference = storage.getReference().child("Users/" +userId +".jpg"); 
Glide.with(UserActivity.this).using(new FirebaseImageLoader()).load(storageReference).into((ImageView) findViewById(R.id.user_photo)); 

無論是從documentation取而第二個似乎更方便。

在日誌中似乎沒有錯誤。

有人能解釋一下這個區別嗎?

This是我對這個主題的唯一其他問題,但它沒有答案。

我使用com.google.firebase:firebase-storage:10.2.6com.firebaseui:firebase-ui-storage:1.2.0

+2

我已經看到,一個人在firebase存儲版本有問題。你可以嘗試將它降級到10.2.1並檢查它是否有效嗎? – cristianorbs

+0

謝謝,它的作品。 –

回答

0

加載使用格萊德我在​​項目中使用這種方法火力地堡存儲器中的圖像。它工作正常:

private void loadImage(){ 
     StorageReference storage = FirebaseStorage.getInstance().getReference(); 
     StorageReference userStorage = storage.child("Users").child(userID); 

     userStorage.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() { 
      @Override 
      public void onSuccess(Uri uri) { 
       Glide.with(context).load(uri.toString()).into(profileImage); 
      } 
     }).addOnFailureListener(new OnFailureListener() { 
      @Override 
      public void onFailure(@NonNull Exception exception) { 
       // failed 
      } 
     }); 
    } 
+1

這基本上是OP提到的方法 – cristianorbs