get Image File Path by Uri - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

get Image File Path by Uri

Demo Code

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class Main {

  public static String getImageFilePath(Context context, Uri uri) {
    String path = null;/*from  w ww  . j av  a2s  .c o m*/
    Cursor cursor = null;

    try {
      cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.Media.DATA }, null, null, null);
      cursor.moveToFirst();

      path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
    } finally {
      cursor.close();
    }

    return path;
  }

}

Related Tutorials