如何从 URI 获取完整文件路径 [英] How to get the Full file path from URI

查看:20
本文介绍了如何从 URI 获取完整文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 URI 获取完整的文件路径.URI 不是图像,而是音乐文件,但如果我像 MediaStore 解决方案一样这样做,如果应用程序用户选择 Astro 作为浏览器而不是音乐播放器,它将无法工作.我该如何解决这个问题?

I'd like to get the full file path, from a URI. The URI isn't a Image, but it's a music file, but if i do it like the MediaStore Solution, it won't work if the app user selects eg Astro as browser, instead of Music Player. How do I solve this?

推荐答案

使用:

String path = yourAndroidURI.uri.getPath() // "/mnt/sdcard/FileName.mp3"
File file = new File(new URI(path));

String path = yourAndroidURI.uri.toString() // "file:///mnt/sdcard/FileName.mp3"
File file = new File(new URI(path));

这篇关于如何从 URI 获取完整文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆