@GlideModule public class GlideCache extends AppGlideModule { @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) ); }
@Override public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { super.registerComponents(context, glide, registry); } private String sdRootPath = Environment.getExternalStorageDirectory().getPath(); private String appRootPath = null; private String getStorageDirectory() { return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ? sdRootPath : appRootPath; }}