How to get the file path from URI? [duplicate] How to get the file path from URI? [duplicate] android android

How to get the file path from URI? [duplicate]


File myFile = new File(uri.toString());myFile.getAbsolutePath()

should return u the correct path

EDIT

As @Tron suggested the working code is

File myFile = new File(uri.getPath());myFile.getAbsolutePath()


Here is the answer to the questionhere

Actually we have to get it from the sharable ContentProvider of Camera Application.

EDIT . Copying answer that worked for me

private String getRealPathFromURI(Uri contentUri) {    String[] proj = { MediaStore.Images.Media.DATA };    CursorLoader loader = new CursorLoader(mContext, contentUri, proj, null, null, null);    Cursor cursor = loader.loadInBackground();    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);    cursor.moveToFirst();    String result = cursor.getString(column_index);    cursor.close();    return result;}