问题
I load image from URL using picasso
first time on line, After then use from cache. Any URL from web is load in imageview
on line or off line. But my server image URL is load image in on line not in off line. I use below code from image load.
Picasso.with(mContext)
.load(urlProfile)
.networkPolicy(NetworkPolicy.OFFLINE)
.placeholder(R.drawable.ic_place_holder)
.into(imageView, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(mContext)
.load(urlProfile)
.placeholder(R.drawable.ic_place_holder)
.into(imageView);
}
});
Web url load in online or offline both : URL
My server url load image only in online: URL
I show in cache directory and found that image of my server URL is not cached. Any have idea about that.
回答1:
Hi below is my solutions and it's working perfectlly.
Picasso.with(mContext)
.load(Uri.parse(urlProfile))
.networkPolicy(NetworkPolicy.OFFLINE)
.into(iv_view, new Callback() {
@Override
public void onSuccess() {
// if you are showing progress then handle it on here
}
@Override
public void onError() {
// Try again online if cache failed and download using internet
new Picasso.Builder(mContext)
.downloader(new OkHttpDownloader(mContext, Integer.MAX_VALUE))
.build()
.load(Uri.parse(urlProfile))
.placeholder(R.mipmap.ic_launcher)
.into(iv_view);
}
});
Hope this helps you..
By the way this is very old but you can use Glide for better performance.
来源:https://stackoverflow.com/questions/47768373/image-from-certain-url-is-not-load-in-picasso