How to integrate Firebase with Glide ('using' method)

南笙酒味 提交于 2019-12-05 18:56:40

问题


I'm trying to use Firebase integration with Glide and for some reason, Glide.using() cannot resolve this method. I did add:

compile 'com.firebaseui:firebase-ui-storage:0.6.0'

Into build.gradle and also:

compile 'com.github.bumptech.glide:glide:4.0.0-RC1'

Here is the part which I'm trying to use Glide:

   mStorageRef = FirebaseStorage.getInstance().getReference();
    mStorageRef.child("images/Puffer-fish-are-pretty-damn-cute.jpg");

// Load the image using Glide
        Glide.with(this)
                .using(new FirebaseImageLoader()) // cannot resolve method using!
                .load(mStorageRef)
                .into(imageView);

I hope you can help me with that, didn't find any solutions online.


回答1:


To solve this, please change this line:

compile 'com.github.bumptech.glide:glide:4.0.0-RC1'

with

compile 'com.github.bumptech.glide:glide:3.7.0'



回答2:


Glide v4 is using module loaders with the annotation processor library.

Create AppGlideModule and then register FirebaseImageLoader. When loading images use StorageReference.

Here it is in details.

Add libraries in gradle

implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.firebaseui:firebase-ui-storage:4.1.0'

Extend the module and register

@GlideModule
public class MyAppGlideModule extends AppGlideModule {

    @Override
    public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
        registry.append(StorageReference.class, InputStream.class, new FirebaseImageLoader.Factory());
    }
}

Load images with ref

Uri uri = Uri.parse(photoUrl);
StorageReference ref = FirebaseStorage.getInstance().getReference().child(uri.getPath());
Glide.with(itemView.getContext())
    .load(ref)
    .into(thumb);


来源:https://stackoverflow.com/questions/44949432/how-to-integrate-firebase-with-glide-using-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!