【发布时间】:2017-05-09 04:50:10
【问题描述】:
我采用了两种方法来使用 glide 从 firebase 存储中获取图像。第一种方法运行良好,因为在获取 downloadUrl 后,它正在使用 glide 加载图像。
但第二个更方便,但它不适合我。
buidl.gradle:应用程序
dependencies {
// ..... not included glige dependency
compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}
第一种方法(工作):
// question.imgQuestion = "qimgs/-KiTpzP5t-xJOO5nSK0A/1493896460324-ch1pg2.jpg"
final StorageReference ref = mStorage.getReference().child(question.imgQuestion);
ref.getDownloadUrl().addOnSuccessListener(this, new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Log.i(TAG, "Download URL : " + uri); // https://firebasestorage.googleapis.com/v0/b/questionpaper-ce229.appspot.com/o/qimgs%2F-KiTpzP5t-xJOO5nSK0A%2F1493896460324-ch1pg2.jpg?alt=media&token=ca2a3f6e-3eb5-4088-a48d-069ac8ad640b
Glide.with(QuizActivity.this)
.load(uri)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(mImageQuestion);
}
});
第二种方法(不起作用,但我想要这个)
// question.imgQuestion = "qimgs/-KiTpzP5t-xJOO5nSK0A/1493896460324-ch1pg2.jpg"
final StorageReference ref = mStorage.getReference().child(question.imgQuestion);
Glide.with(QuizActivity.this)
.using(new FirebaseImageLoader())
.load(ref)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(mImageQuestion);
注意:此 Firebase 存储实例是经过身份验证的实例。
【问题讨论】:
-
代码看起来不错。有任何错误信息吗?考虑添加
RequestListener以获得更多状态。请参阅此问题以获取示例代码:stackoverflow.com/q/43853592/4815718。您也可以尝试使用更新版本的 FirebaseUI 库。最新的是 1.2.0。 -
谢谢,是库版本问题。使用 FirebaseUI 版本:1.2.0 和 Firebase/Play 服务版本:10.2.0。现在它正在工作。
标签: android image firebase firebase-storage android-glide