Search code examples
androidpathgeturi

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?


Solution

  • Use:

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

    or

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