和已有FileProvider共存问题(应该是最后的解决方式了)-希望git主能采用
如果可以自定义FileProvider和对应file_paths.xml文件的,看 #486 这篇,完美解决。 我是自己搭了个通用型lib框架,file_paths.xml名字可以改,但name不想叫camera_photos,但是源码里是写死的,于是改了git主源码,动态获取。
1、自己的改了名的file_paths.xml,paths标签下的一定只留下root-path标签,name随便(path得看你有没有root权限了)。`
2、修改takephoto_library里的tiul.TuriParse.java 122行 `
// TODO: 19/7/12 Cong2011修改-动态替换uri头
String[] np = getRootNamePath(context);
path = new File(uri.getPath().replace(np[0] + "/", TextUtils.isEmpty(np[1]) ? "" : np[1] + "/")).getAbsolutePath();
// path = new File(uri.getPath().replace("camera_photos/", "")).getAbsolutePath();`
`
private static String[] rootPath;
private static String[] getRootNamePath(Context context) {
if (rootPath != null) return rootPath;
try {
final String authority = TConstant.getFileProviderName(context);
final ProviderInfo info = context.getPackageManager()
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
final XmlResourceParser in = info.loadXmlMetaData(
context.getPackageManager(), "android.support.FILE_PROVIDER_PATHS");
if (in == null) {
throw new IllegalArgumentException(
"Missing " + "android.support.FILE_PROVIDER_PATHS" + " meta-data");
}
int type;
while ((type = in.next()) != END_DOCUMENT) {
if (type != START_TAG) continue;
final String tag = in.getName();
final String name = in.getAttributeValue(null, "name");
String path = in.getAttributeValue(null, "path");
if ("root-path".equals(tag)) {
return rootPath = new String[]{name, path};
}
}
throw new IllegalStateException("FILE_PROVIDER_PATHS 中未配制root-path标签");
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
throw new IllegalArgumentException(
"Missing " + "android.support.FILE_PROVIDER_PATHS" + " meta-data");
}
}
`
"return new String[]{name, path};"改成“return rootPath = new String[]{name, path};”。。犯了低级错误,忘保存了
提pr啊。。。。
提pr啊。。。。
是的,通过动态提取其中起作用的root-path配制,解决冲突问题
自己定义一个FileProvider继承FileProvider 然后自己的项目就用自己定义的FileProvider 这样就跟依赖的lib不冲突了,还不用去改源码
自己定义一个FileProvider继承FileProvider 然后自己的项目就用自己定义的FileProvider 这样就跟依赖的lib不冲突了,还不用去改源码