我想从互联网加载Picasso的图片,没有连接,从磁盘缓存。缓存写得很好(图片在缓存目录中)。但是在阅读时我得到了这个日志:
Sending progress READING_FROM_CACHE
Cache content not available or expired or disabled
我在项目中对请求进行了改造和确认。这张图片加载了 CODE :
// Obtain the cache directory
File cacheDir = getActivity().getCacheDir();
// Create a response cache using the cache directory and size restriction
HttpResponseCache responseCache = null;
try {
responseCache = new HttpResponseCache(
cacheDir,
10 * 1024 * 1024);
} catch (IOException e) {
e.printStackTrace();
}
// Prepare OkHttp
OkHttpClient httpClient = new OkHttpClient();
httpClient.setResponseCache(responseCache);
// Build Picasso with this custom Downloader
Picasso picasso = new Picasso.Builder(getActivity())
.downloader(new OkHttpDownloader(httpClient))
.build();
picasso.setDebugging(true);
picasso.with(getActivity())
.load(profilePicUrl) // url picture
.resize(180, 180)
.centerCrop()
.placeholder(R.drawable.ic_int_profile_no_photo)
.into(mProfilePic); //ImageView
结果是没有连接,图片不加载,但图片在picasso的缓存目录中(日志显示该信息)。
的观
我认为如果我使用Picasso的自定义下载,我不必修改我的改装请求标头(RequestInterceptor - >拦截)。我有很多POST和GET请求,我希望保持原样。
我检查过的一些链接
How to implement my own disk cache with picasso library - Android?
https://github.com/square/picasso/issues/237
How to retrieve images from cache memory in picasso?
提前谢谢。