2017-05-29 67 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