Using Firebase Storage image with Glide

五迷三道 提交于 2019-11-27 23:52:41

Change this:

 implementation 'com.firebaseui:firebase-ui-storage:2.0.1'

to this:

  implementation 'com.firebaseui:firebase-ui-storage:3.2.1'

According to the Glide docs:

using()

The using() API was removed in Glide 4 to encourage users to register their components once with a AppGlideModule to avoid object re-use. Rather than creating a new ModelLoader each time you load an image, you register it once in an AppGlideModule and let Glide inspect your model (the object you pass to load()) to figure out when to use your registered ModelLoader.

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() was removed from Glide 4.

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

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

more info here: https://github.com/firebase/FirebaseUI-Android/tree/master/storage

As for Glide 4.6.1 you can't use .using(new FirebaseImageLoader())

I am force to downgrade to

implementation 'com.github.bumptech.glide:glide:3.8.0'

and Firebase UI implementation'com.firebaseui:firebase-ui-storage:2.0.1'

nburn42

The answers above didn't help me.

I was missing this in my gradle.

annotationProcessor 'com.github.bumptech.glide:compiler:4.x'

The best docs I have found are here

If you've uploaded little images for icons on to your Firebase storage, get rid off glide and that "model". It makes a lot of changes on its git. So your code should look like:

   StorageReference referenseLcl = FirebaseStorage.getInstance().getReference();
                StorageReference islandRefLcl = referenseLcl.child(userLcl.getImageIconPath());
                final long ONE_MEGABYTE = 1024 * 1024;
                islandRefLcl.getBytes(ONE_MEGABYTE).addOnSuccessListener(bytesPrm -> {
                    Bitmap bmp = BitmapFactory.decodeByteArray(bytesPrm, 0, bytesPrm.length);
                    imageOfUser.setImageBitmap(bmp);
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        imageOfUser.setImageResource(R.mipmap.ic_launcher);
                    }
                });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!