困扰了很多天的问题,网上也找了很多技术帖看,但很多都是零零散散,下面我就把我解决过程中遇到的问题点跟大家说一下。
一、添加依赖:
- compile ‘com.github.bumptech.glide:glide:3.7.0’
- compile ‘com.squareup.okhttp:okhttp:2.7.5’ //添加okhttp3会出现问题具体下面会说
二、重写需要的类:
1、
public class OkHttpGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// Do nothing.
}
@Override
public void registerComponents(Context context, Glide glide) {
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
2、
public class OkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
/**
* The default factory for {@link OkHttpUrlLoader}s.
*/
public static class Factory implements ModelLoaderFactory<GlideUrl, InputStream> {
private static volatile OkHttpClient internalClient;
private OkHttpClient client;
private static OkHttpClient getInternalClient() {
if (internalClient == null) {
synchronized (Factory.class) {
if (internalClient == null) {
internalClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();
}
}
}
return internalClient;
}
/**
*