问题描述
我几乎尝试了所有答案,但有很多重复的答案,但是我仍然无法在Glide中使用Firebase存储映像.
There are tons of duplicated answers I had tried almost all of them but I am still not able to use Firebase storage image with Glide.
首先我正在使用文档
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReference();
StorageReference pathReference = storageRef.child("sorular/1.jpg");
// ImageView in your Activity
ImageView imageView = rootView.findViewById(R.id.imageView);
// Load the image using Glide
Glide.with(this /* context */)
.using(new FirebaseImageLoader()) // Cannot resolve method 'using
.load(pathReference)
.into(imageView);
如果我清理了Glide的.using部分,logcat会显示此错误:
if I clean the .using part of Glide, logcat it gives this error:
那么如何才能以最佳方式在我的android应用中使用firebase存储映像?
So how can use firebase storage images in my android app in a best way?
这也是我的构建gradle依赖项:
also this my build gradle dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:palette-v7:27.0.2'
implementation "com.android.support:cardview-v7:27.0.2"
implementation "com.android.support:recyclerview-v7:27.0.2"
implementation "com.android.support:support-v4:27.0.2"
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.github.florent37:materialviewpager:1.2.3'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.firebaseui:firebase-ui-storage:2.0.1'
implementation 'com.google.firebase:firebase-auth:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
推荐答案
更改此内容:
implementation 'com.firebaseui:firebase-ui-storage:2.0.1'
对此:
implementation 'com.firebaseui:firebase-ui-storage:3.2.1'
根据Glide文档:
using()
要确保仅对某些模型使用ModelLoader,请实施上述的handles()来检查每个模型,并仅在应使用ModelLoader时才返回true.
To make sure you only use your ModelLoader for certain models, implement handles() as shown above to inspect each model and return true only if your ModelLoader should be used.
using()
已从Glide 4中删除.
using()
was removed from Glide 4.
要解决此问题,您需要执行以下操作:要从StorageReference加载图像,请首先注册一个AppGlideModule:
To Solve this, you need to do this:To load an image from a StorageReference, first register an AppGlideModule:
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
}
}
一旦创建了AppGlideModule类并完成了干净的构建,就可以使用GlideApp将StorageReference加载到ImageView中:
Once you have created an AppGlideModule class and done a clean build, you can use GlideApp to load a StorageReference into an ImageView:
// Reference to an image file in Cloud Storage
StorageReference storageReference = ...;
// ImageView in your Activity
ImageView imageView = ...;
// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
GlideApp.with(this /* context */)
.load(storageReference)
.into(imageView);
此处的更多信息: https://github.com/firebase/FirebaseUI- Android/tree/master/storage
这篇关于将Firebase Storage映像与Glide一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!