Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.database.Cursor; import android.net.Uri; import android.provider.MediaStore; import java.io.File; public class Main { public static File uri2File(Activity context, Uri uri) { File file; String[] project = { MediaStore.Images.Media.DATA }; Cursor actualImageCursor = context.getContentResolver().query(uri, project, null, null, null); if (actualImageCursor != null) { int actual_image_column_index = actualImageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualImageCursor.moveToFirst(); String img_path = actualImageCursor.getString(actual_image_column_index); file = new File(img_path); } else { file = new File(uri.getPath()); } if (actualImageCursor != null) actualImageCursor.close(); return file; } }