Android 微信通过第三方的软件打开,获取文件路径

 微信的返回的fileprovider地址"content://com.tencent.mm.external.fileprovider/""content://0@com.tencent.mm.external.fileprovider/"
	//通过微信URI解析文件地址public static String uriToFile(Context context, Uri uri) {try {File file = null;if (uri == null) return null;//获得ContentResolver,用于访问其它应用数据ContentResolver resolver = context.getContentResolver();//获得URI路径String pathUri = uri.getPath().toLowerCase();//从路径中提取文件名+文件扩展名String displayName = getFileName(pathUri) + "." + getExtensionName(pathUri);//解析微信文件路径if (uri.toString().toLowerCase().startsWith("content://com.tencent.mm.external.fileprovider/") || uri.toString().toLowerCase().startsWith("content://0@com.tencent.mm.external.fileprovider/")) {try {InputStream is = resolver.openInputStream(uri);File cache = new File(context.getCacheDir().getAbsolutePath(), displayName);FileOutputStream fos = new FileOutputStream(cache);//android.os.FileUtils不是工具类,是Android的SDK方法android.os.FileUtils.copy(is, fos);file = cache;fos.close();is.close();} catch (IOException e) {e.printStackTrace();}return file.toString();}} catch (Exception e) {e.printStackTrace();}return null;}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部