tim687 tim687 - 2 months ago 24
Android Question

How to get the Full file path from URI

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?

Answer

Use:

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

or

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