Android default device storage path acquisition method

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());

Output 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,

That is, getCacheDir() corresponds to the /data/user/0/com.cnki.android.cnkimobile/cache directory

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

And getExternalCacheDir() corresponds to the Android/data/com.cnki.android.cnkimobile/cache directory under the root directory of the mobile phone


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

Guess you like

Origin blog.csdn.net/yeziyfx/article/details/106806194