在 Glide 中添加自定义 OkHttpClient
Add custom OkHttpClient in Glide
我想知道是否可以让 Glide
使用我在 Application class
中注册和创建的 OkHttpClient
?
因为我们有一个相当复杂的 OkHttpClient
它被我们的服务层使用,我们想使用它而不是让 Glide 使用它自己的。
是否可以将其注册为自定义模块?
OkHttp version: 2.5.0
Glide version: 3.6.1
为了设置正确的 OkHttpClient,我选择使用 Picasso (2.5.2)。类似的库,所以为了我们的使用,我们选择了 Picasso。
因为我们使用的是旧版本的 OkHttp,目前还不能更新到 OkHttp 3+。
在 CustomApplication class 中调用 onCreate()
private void setupPicasso()
{
final Picasso picasso = new Picasso.Builder(getApplicationContext())
.downloader(new OkHttpDownloader(getPrimaryHttpClient()))
.build();
Picasso.setSingletonInstance(picasso);
}
Gradle 导入:
compile 'com.squareup.picasso:picasso:2.5.2'
所以现在正在使用正确的客户端,并且图像按预期工作。
我希望这至少能对任何人有所帮助。
我想知道是否可以让 Glide
使用我在 Application class
中注册和创建的 OkHttpClient
?
因为我们有一个相当复杂的 OkHttpClient
它被我们的服务层使用,我们想使用它而不是让 Glide 使用它自己的。
是否可以将其注册为自定义模块?
OkHttp version: 2.5.0
Glide version: 3.6.1
为了设置正确的 OkHttpClient,我选择使用 Picasso (2.5.2)。类似的库,所以为了我们的使用,我们选择了 Picasso。
因为我们使用的是旧版本的 OkHttp,目前还不能更新到 OkHttp 3+。
在 CustomApplication class 中调用 onCreate()
private void setupPicasso()
{
final Picasso picasso = new Picasso.Builder(getApplicationContext())
.downloader(new OkHttpDownloader(getPrimaryHttpClient()))
.build();
Picasso.setSingletonInstance(picasso);
}
Gradle 导入:
compile 'com.squareup.picasso:picasso:2.5.2'
所以现在正在使用正确的客户端,并且图像按预期工作。
我希望这至少能对任何人有所帮助。