如何在Picasso中使用磁盘缓存?我正在使用毕加索(Picasso)在我的Android应用程序中显示图像:/**
* load image.This is within a activity so this context is activity
*/public void loadImage (){
Picasso picasso = Picasso.with(this);
picasso.setDebugging(true);
picasso.load(quiz.getImageUrl()).into(quizImage);}我已经启用了调试,它总是显示红色和绿色,但从不显示黄色现在,如果我加载相同的图像,下次,互联网是不可用的,图像是不加载的。问题:它没有本地磁盘缓存吗?如何启用磁盘缓存,因为我将多次使用相同的映像。是否需要向Android清单文件添加一些磁盘权限?
3 回答
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
compile 'com.squareup.picasso:picasso:2.5.2'compile 'com.squareup.okhttp3:okhttp:3.10.0'compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
Application
import android.app.Application;import com.jakewharton.picasso.OkHttp3Downloader;import com.squareup.picasso.Picasso;public class Global extends Application { @Override public void onCreate() { super.onCreate(); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttp3Downloader(this,Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(true); built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); }}
<application android:name=".Global" .. ></application>
编辑:
Picasso.with(this) .load(url) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView);
编辑#2
Picasso.with(getActivity()).load(imageUrl).networkPolicy(NetworkPolicy.OFFLINE).into(imageView, new Callback() { @Override public void onSuccess() { } @Override public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Override public void onSuccess() { } @Override public void onError() { Log.v("Picasso","Could not fetch image"); } }); }});
- 3 回答
- 0 关注
- 323 浏览
添加回答
举报
0/150
提交
取消