原
glide 设置缓存路径
按照教程在build.gradle内添加
implementation 'com.github.bumptech.glide:glide:4.5.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
新建个类继承AppGlideModule
-
@GlideModule
-
public
class GlideCache extends AppGlideModule {
-
@Override
-
public void applyOptions(Context context, GlideBuilder builder) {
-
super.applyOptions(context, builder);
-
}
-
-
@Override
-
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
-
super.registerComponents(context, glide, registry);
-
}
-
}
-
@Override
-
public void applyOptions(Context context, GlideBuilder builder) {
-
int diskCacheSizeBytes =
1024 *
1024 *
100;
// 100 MB
-
//手机app路径
-
appRootPath = context.getCacheDir().getPath();
-
builder.setDiskCache(
-
new DiskLruCacheFactory( getStorageDirectory()+
"/GlideDisk", diskCacheSizeBytes )
-
);
-
-
}
-
//外部路径
-
private String sdRootPath = Environment.getExternalStorageDirectory().getPath();
-
private String appRootPath =
null;
-
-
private String getStorageDirectory(){
-
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ?
-
sdRootPath : appRootPath;
-
}