FileChoose
FileChoose copied to clipboard
第三方文件管理器Uri转File优化,可兼容迅雷和QQ浏览器,其他的感觉应该类似
https://github.com/DB-BOY/FileChoose/blob/1125d8717bd2a616e9132d6272aa48c06cf569c8/app/src/main/java/cn/dbboy/filechoose/FileUtil.java#L109
改成:
File thirdPartyUriFile = getThirdPartyUriFile(uri);
if (thirdPartyUriFile != null) {
return thirdPartyUriFile.toString();
}
/**
* 处理第三方文件管理器的文件Uri
*
* @param uri
*
* @return
*/
public static File getThirdPartyUriFile(Uri uri) {
String path = uri.getPath();
if (!TextUtils.isEmpty(path)) {
// 去掉第一个'/'
path = path.substring(1);
// 去掉新path第一个'/'前面的内容
path = path.substring(path.indexOf('/'));
File file = new File(Environment.getExternalStorageDirectory(), path);
if (file.exists()) {
return file;
}
}
return null;
}