Getting Image from Firebase Storage using Glide

前端 未结 3 1714
渐次进展
渐次进展 2020-12-06 06:47

I am trying to load an image from Firebase Storage using Glide but I am getting an error .

package com.kanishq.wallpaper;
import android.os.Bundle;
import an         


        
3条回答
  •  [愿得一人]
    2020-12-06 07:24

    ( KOTLIN ) It was not mentioned anywhere in the Docs but to have to load images directly from Cloud Storage to your App using Glide you have to include three lines in app build.gradle (in addition to other Firebase dependencies):

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
    

    Though you are adviced to use kotlin - kapt instead of annotationProcessor for Kotlin.

    Then some where in your Project add this class for Firebase Loader. Note that the annotation is very important for the class:

    package com.your.package.name
    
    import android.content.Context
    import com.bumptech.glide.Glide
    import com.bumptech.glide.Registry
    import com.bumptech.glide.annotation.GlideModule
    import com.bumptech.glide.module.AppGlideModule
    import com.firebase.ui.storage.images.FirebaseImageLoader
    import com.google.firebase.storage.StorageReference
    import java.io.InputStream
    
    
    @GlideModule
    class MyAppGlideModule : AppGlideModule() {
        override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
            registry.append(
                StorageReference::class.java, InputStream::class.java,
                FirebaseImageLoader.Factory()
            )
        }
    }
    

    Then you can use it as:

    Glide.with(this /* context */)
        .load(storageReference)
        .into(imageView)
    

    Any errors? Update the dependencies above also Invalidate Cache and Restart your Android Studio.

提交回复
热议问题