
我正在使用glIDe v4和okhttp3与glIDe集成.我想更改它的超时时间.怎么做?通过扩展AppGlIDeModule还是还有其他方法?我已经搜索了正确的文档,但没有找到任何地方.
解决方法:
您可以通过创建一个类来更改超时,该类扩展了AppGlIDeModule并具有@GlIDeModule批注.然后,您覆盖方法registerComponents并在其中内部,可以创建一个新的OkhttpClIEnt,可用于控制GlIDe请求超时.
首先,您应该在build.gradle文件中添加GlIDe和Okhttp3 GlIDe Integration库gradle依赖项:
compile 'com.github.bumptech.glIDe:glIDe:4.2.0'annotationProcessor 'com.github.bumptech.glIDe:compiler:4.2.0'compile("com.github.bumptech.glIDe:okhttp3-integration:4.2.0") { exclude group: 'glIDe-parent'}第二,自定义GlIDeAppModule类的示例代码:
@GlIDeModulepublic class MyGlIDeAppModule extends AppGlIDeModule { @OverrIDe public voID registerComponents(Context context, GlIDe glIDe, Registry registry) { OkhttpClIEnt clIEnt = new OkhttpClIEnt.Builder() .connectTimeout(20, TimeUnit.SECONDS) .readTimeout(20, TimeUnit.SECONDS) .build(); OkhttpUrlLoader.Factory factory = new OkhttpUrlLoader.Factory(clIEnt); glIDe.getRegistry().replace(GlIDeUrl.class, inputStream.class, factory); }}感谢提供解决方案的Amir Ziarati!
另外,有关GlIDe 3.x和GlIDe 4.x之间差异的更多信息,请参考关于模块的GlIDe自定义的this article.
总结以上是内存溢出为你收集整理的如何使用Okhttp3和GlideV4设置超时?全部内容,希望文章能够帮你解决如何使用Okhttp3和GlideV4设置超时?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)