Search code examples
androiduriexternalfile-uri

Converting file:// scheme to content:// scheme


I am running to the problem with using Droid X's Files app and Astro file manager to select an image file. This two apps return the selected image with the scheme "file://" while Gallery returns the image with the scheme "content://". How do I convert the first schema to the second. Or how do I decode the image with the second format?


Solution

  • You probably want to convert content:// to file://

    For gallery images, try something like this:

    Uri myFileUri;
    Cursor cursor = context.getContentResolver().query(uri,new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
    if(cursor.moveToFirst())
    {
        myFileUri = Uri.parse(cursor.getString(0)).getPath();
    }
    cursor.close