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

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

问题描述

我想获得完整的文件路径,从一个URI。 URI是不是一个图像,但它是一个音乐文件,但如果我这样做,如MediaStore解决方案,它不会,如果应用程序用户选择,而不是音乐播​​放器如天文浏览器,正常工作。我该如何解决这个问题?

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() // "file:///mnt/sdcard/FileName.mp3"
File file = new File(new URI(path));

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

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

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