-
name 可以自定义
-
path 基于当前标签代表的路径作为父目录 的目录
如
external-path
:/storage/emulated/0,代表存储根目录,若 path = "download" 那么共享的目录为 /storage/emulated/0/path/
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<paths>
<external-path
name="external_storage_root"
path="">
<!--Environment.getExternalStorageDirectory()-->
<!--/storage/emulated/0-->
<!--存储的根目录-->
</external-path>
<files-path>
<!--context.getFilesDir()-->
<!--内部存储的files目录-->
<!--/data/user/0/com.stone.testdemo/files-->
</files-path>
<cache-path>
<!--context.getCacheDir()-->
<!--内部存储的cache目录-->
<!--/data/user/0/com.stone.testdemo/cache-->
</cache-path>
<external-files-path>
<!--ContextCompat.getExternalFilesDirs-->
<!--外部私有存储的files目录-->
<!--/storage/emulated/0/Android/data/com.stone.testdemo/files-->
</external-files-path>
<external-cache-path>
<!--ContextCompat.getExternalCacheDirs-->
<!--外部私有存储的cache目录-->
<!--/storage/emulated/0/Android/data/com.stone.testdemo/cache-->
</external-cache-path>
<external-media-path>
<!--context.getExternalMediaDir-->
<!--/storage/emulated/0/Android/media/com.stone.testdemo-->
</external-media-path>
</paths>
</resources>
源码
FileProvider#parsePathStrategy中关于共享路劲的解析逻辑部分
File target = null;
if ("root-path".equals(tag)) {
target = DEVICE_ROOT;
} else if ("files-path".equals(tag)) {
target = context.getFilesDir();
} else if ("cache-path".equals(tag)) {
target = context.getCacheDir();
} else if ("external-path".equals(tag)) {
target = Environment.getExternalStorageDirectory();
} else {
File[] externalMediaDirs;
if ("external-files-path".equals(tag)) {
externalMediaDirs = ContextCompat.getExternalFilesDirs(context, (String)null);
if (externalMediaDirs.length > 0) {
target = externalMediaDirs[0];
}
} else if ("external-cache-path".equals(tag)) {
externalMediaDirs = ContextCompat.getExternalCacheDirs(context);
if (externalMediaDirs.length > 0) {
target = externalMediaDirs[0];
}
} else if (VERSION.SDK_INT >= 21 && "external-media-path".equals(tag)) {
externalMediaDirs = context.getExternalMediaDirs();
if (externalMediaDirs.length > 0) {
target = externalMediaDirs[0];
}
}
}
网友评论