I. briefly
In Android development, you often need to operate files. You have been unclear about the corresponding relationship between api and file path. Today, you have time to sort out the records so as not to forget them later.
ps: since there is no machine with SD card in hand, the following test results are all on the mobile phone without external SD card
2, Start testing
First look at the following code
ps: the following test models are Vivo X9(android 7.1.2 api 25) and MeiZu M3(android 5.1 api 22)
getFilesDir(); getExternalCacheDir(); getPackageCodePath(); getPackageResourcePath(); getCacheDir(); getExternalFilesDir(null); Environment.getExternalStorageState(); Environment.getExternalStorageDirectory(); Environment.getDataDirectory(); Environment.getDownloadCacheDirectory(); Environment.getRootDirectory(); Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
The paths corresponding to the above tests are:
vivomeizu
Through the above observation, it can be found that there are several api models that are slightly different. The customized system of domestic manufacturers has been modified correspondingly. When using it, it is still necessary to be careful to prevent "dropping pit".
Here, Tucao CSDN picture is too bad, the picture format is not good enough to adjust.
Environment.getDataDirectory() = /data Environment.getDownloadCacheDirectory() = /data/cache (vivo) /cache (meizu) Environment.getExternalStorageDirectory() = /storage/emulated/0 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) = /storage/emulated/0/Pictures Environment.getRootDirectory() = /system getPackageCodePath() = /data/app/com.demo.mydemoapplication-1/base.apk getPackageResourcePath() = /data/app/com.demo.mydemoapplication-1/base.apk getCacheDir() = /data/data/com.demo.mydemoapplication/cache (meizu) /data/user/0/com.demo.mydemoapplication/cache (vivo) getDatabasePath("test") = /data/data/com.demo.mydemoapplication/databases/test getDir("test", Context.MODE_PRIVATE) = /data/data/com.demo.mydemoapplication/app_test getExternalCacheDir() = /storage/emulated/0/Android/data/com.demo.mydemoapplication/cache getExternalFilesDir("test") = /storage/emulated/0/Android/data/com.demo.mydemoapplication/files/test getExternalFilesDir(null) = /storage/emulated/0/Android/data/com.demo.mydemoapplication/files getFilesDir() = /data/data/com.demo.mydemoapplication/files (meizu) /data/user/0/com.demo.mydemoapplication/files (vivo)