在毕加索,我使用OkHttp来请求网络。我希望将我的图像缓存在毕加索中。但我也希望在我的OkHttpClient中使用日志拦截器。
要在OkHttp中添加日志拦截器,我这样做:
OkHttpClient provideOkHttpClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
return httpClient.build();
}
要在毕加索中添加缓存,我以这种方式使用new OkHttp3Downloader(context, Integer.MAX_VALUE)
:
Picasso providePicasso(Context context, OkHttpClient httpClient) {
Picasso.Builder builder = new Picasso.Builder();
builder.downloader(new OkHttp3Downloader(context, Integer.MAX_VALUE));
Picasso built = builder.build();
Picasso.setSingletonInstance(built);
}
我如何提供:
a)缓存
b)OkHttpClient
要OkHttp3Downloader
,以便我可以缓存Picasso请求,并使用OkHttp
Picasso请求进行记录?
答案 0 :(得分:-1)
您可以使用httpClient作为下载程序:
builder.downloader(yourClass.provideOkHttpClient());