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

KITT picture KITT · Jun 10, 2011 · Viewed 11.9k times · Source

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?

Answer

cjb picture cjb · Jun 10, 2011

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