序号 | api | 路径 |
---|---|---|
1 | Environment.getDataDirectory().getAbsolutePath() | /data |
2 | Environment.getDownloadCacheDirectory().getAbsolutePath() | /data/cache |
3 | getPackageCodePath() | /data/app/com.example.t001-L3Hbdf4sz06WYM_KKyyKWg==/base.apk |
4 | getPackageResourcePath() | /data/app/com.example.t001-L3Hbdf4sz06WYM_KKyyKWg==/base.apk |
5 | getCacheDir().getAbsolutePath() | /data/user/0/com.example.t001/cache |
6 | getFilesDir().getAbsolutePath() | /data/user/0/com.example.t001/files |
7 | getDatabasePath(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() | /data/user/0/com.example.t001/databases/Documents |
8 | Environment.getExternalStorageDirectory().getAbsolutePath() | /storage/emulated/0 |
9 | Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() | /storage/emulated/0/Documents |
10 | getExternalCacheDir().getAbsolutePath() | /storage/emulated/0/Android/data/com.example.t001/cache |
11 | getExternalFilesDir(“test”).getAbsolutePath() | /storage/emulated/0/Android/data/com.example.t001/files/test |
/data/user/0 指向data/data,data/user/0是data/data的快捷方式;
卸载该app后(com.example.t001),data/data/com.example.t001(内部存储中的某个应用的存储目录)和/storage/emulated/0/Android/data/com.example.t001(外部存储中某个应用的存储目录)会自动删除;
代码
Log.d(TAG, "01-" + Environment.getDataDirectory().getAbsolutePath());
Log.d(TAG, "02-" + Environment.getDownloadCacheDirectory().getAbsolutePath());
Log.d(TAG, "------------------------------------------------------------------");
Log.d(TAG, "03-" + getPackageCodePath());
Log.d(TAG, "04-" + getPackageResourcePath());
Log.d(TAG, "------------------------------------------------------------------");
Log.d(TAG, "--------------/data/user/0 -指向> data/data-----------------");
Log.d(TAG, "05-" + getCacheDir().getAbsolutePath()); ///data/user/0/com.example.t001/cache
Log.d(TAG, "06-" + getFilesDir().getAbsolutePath()); ///data/user/0/com.example.t001/files
Log.d(TAG, "07-" + getDatabasePath(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath());///data/user/0/com.example.t001/databases/Documents
Log.d(TAG, "------------------------------------------------------------------");
Log.d(TAG, "08-" + Environment.getExternalStorageDirectory().getAbsolutePath());
Log.d(TAG, "09-" + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath());
Log.d(TAG, "10-" + getExternalCacheDir().getAbsolutePath());
Log.d(TAG, "11-" + getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath());
另外
sdcard 指向 /storage/self/primary;sdcard相当于快捷方式
/storage/self/primary 中的primary又是/mnt/user/0/primary的快捷方式
所以sdcard->/storage/self/primary->/mnt/user/0/primary 相当于同一个目录;
测试手机系统(手持定制机):8.1.0,不同设备/storage/self/primary指向有点不同,有的机器(红米k30)指向/storage/emulated/0(这里因为设备没有root,/storage/emulated/0看不到,猜想有可能也指向/mnt/user/0/primary)
仅此记录,方便查阅