Fresco集成Okhttp3
16lz
2021-01-26
Fresco自定义网络加载
Image pipeline 默认使用HttpURLConnection。应用可以根据自己需求使用不同的网络库,以下是集成Okhttp的示例:
Demo地址
OkHttp
OkHttp 是一个流行的开源网络请求库。Image
pipeline有一个使用OkHttp替换掉了Android默认的网络请求的补充。
如果需要使用OkHttp,使用下面的依赖配置
For OkHttp3:
dependencies { // your project's other dependencies compile "com.facebook.fresco:imagepipeline-okhttp3:0.12.0+"}
配置 image pipeline
配置Image
pipeline这时也有一些不同,不再使用ImagePipelineConfig.newBuilder
,而是使用OkHttpImagePipelineConfigFactory
:
在自定义Application中或者在activity->Oncreate方法中setContentView之前添加:
OkHttpClient mOkHttpClient = new OkHttpClient(); Set listeners = new HashSet<>(); listeners.add(new RequestLoggingListener()); ImagePipelineConfig config = OkHttpImagePipelineConfigFactory .newBuilder(this, mOkHttpClient) .setDownsampleEnabled(true) .setRequestListeners(listeners) .build(); Fresco.initialize(this, config);
更多相关文章
- 【Android(安卓)开源系列】之网络请求框架
- Android(安卓)cmake编译FFmpeg
- android 从顶层到底层 学习笔记--- framework架构
- ubuntu10.04下在配置android与opencv2.2.0
- 工欲善其事必先利其器之Android环境搭建
- android wifi scan and auto re-connect
- Android中如何给layout资源文件分类 在layout下创建子文件夹
- android UVC h264 ffmpeg软解码
- Android(安卓)- 判断当前网络环境、隐藏软键盘、动态监测及获取