Fresco缓存路径(SD、自定义)

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        //设置自定义缓存地址
        DiskCacheConfig images = DiskCacheConfig.newBuilder(this)
                .setBaseDirectoryName("images")//设置文件夹名
                .setBaseDirectoryPath(Environment.getDataDirectory())//设置缓存路径(sd)
                .build();

        ImagePipelineConfig build = ImagePipelineConfig.newBuilder(this)
                .setMainDiskCacheConfig(images)
                .build();

        Fresco.initialize(this,build);
    }
}

自定义缓存路径只需在setBaseDirectoryPath换成下面这个方法

.setBaseDirectoryPath(Environment.getExternalStorageState(file))//自定义路径

你可能感兴趣的:(Fresco缓存路径(SD、自定义))