Android 默认的设备存储路径获取方法

boolean b1=Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
boolean b2=Environment.isExternalStorageRemovable();
File f1= CnkiApplication.getInstance().getCacheDir();
File f2= CnkiApplication.getInstance().getExternalCacheDir();
File file = !b1 &&b2 ?f1:f2;
LogSuperUtil.i(Constant.LogTag.cnki_articles,"b1="+b1+",b2="+b2);
LogSuperUtil.i(Constant.LogTag.cnki_articles,"f1="+f1.getAbsolutePath()+",f2="+f2.getAbsolutePath());
LogSuperUtil.i(Constant.LogTag.cnki_articles,"file="+file.getAbsolutePath());

输出log:

b1=true,b2=false


2020-06-17 14:01:35.320 I: xxx.activity.AddAcademiaMomentActivity$4.onData(AddAcademiaMomentActivity.java:485)->

f1=/data/user/0/com.cnki.android.cnkimobile/cache,

即getCacheDir()对应的是/data/user/0/com.cnki.android.cnkimobile/cache目录

f2=/storage/emulated/0/Android/data/com.cnki.android.cnkimobile/cache

而getExternalCacheDir()对应的是手机根目录下的Android/data/com.cnki.android.cnkimobile/cache目录


2020-06-17 14:01:35.320 I: xxx.activity.AddAcademiaMomentActivity$4.onData(AddAcademiaMomentActivity.java:486)->

file=/storage/emulated/0/Android/data/com.cnki.android.cnkimobile/cache

你可能感兴趣的:(Android基础)