get Photo Path By Local Uri - Android android.hardware

Android examples for android.hardware:Photo

Description

get Photo Path By Local Uri

Demo Code

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

public class Main {

  public static String getPhotoPathByLocalUri(Context context, Intent data) {
    Uri selectedImage = data.getData();/*w w  w . j a  v  a2  s  .c  o  m*/
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    cursor.moveToFirst();
    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();
    return picturePath;
  }

}

Related Tutorials