How to set OkHttpClient for glide

后端 未结 5 1082
不思量自难忘°
不思量自难忘° 2020-12-05 17:45

I am using Glide to load images, the issue I\'m facing is that when i run app on slow internet connection I\'m getting SocketTimeOutException. So to solve this

5条回答
  •  有刺的猬
    2020-12-05 18:09

    Based on the docs, this is the proper up-to-date way to do it:

    @GlideModule
    @Excludes(OkHttpLibraryGlideModule::class)
    class MyGlideModule : AppGlideModule() {
    
      override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        registry.replace(
          GlideUrl::class.java,
          InputStream::class.java,
          OkHttpUrlLoader.Factory(myOkHttpClient)
        )
      }
    }
    

    And you'll need all these dependencies:

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'
    

提交回复
热议问题