DB-BOY / FileChoose

选择文件 com.tencent.mtt.fileprovider
32 stars 27 forks source link

第三方文件管理器Uri转File优化,可兼容迅雷和QQ浏览器,其他的感觉应该类似 #2

Open szitguy opened 4 years ago

szitguy commented 4 years ago

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;
}