【问题标题】:Android Firebase UI image loading not workingAndroid Firebase UI 图像加载不起作用
【发布时间】:2017-05-30 01:28:25
【问题描述】:

我可以使用以下代码从 Firebase 存储加载图像:

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

【问题讨论】:

  • 我看到有人在 firebase-storage 版本上遇到问题。您可以尝试将其降级到 10.2.1 并检查它是否有效?
  • 谢谢,它有效。

标签: android firebase firebase-storage firebaseui


【解决方案1】:

为了使用 Glyde 从 Firebase 存储加载图像,我在我的项目中使用了这种方法。它工作正常:

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
            }
        });
    }

【讨论】:

  • 这基本上是 OP 提到的可行的方法
猜你喜欢
  • 1970-01-01
  • 2019-05-29
  • 1970-01-01
  • 2018-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多