get Image Path From Uri - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

get Image Path From Uri

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;

public class Main{

    public static String getImagePathFromUri(Context context, Uri uri) {
        String path = null;/*from   w w w  .  j  av a 2  s.  c o m*/
        String[] projection = { MediaStore.MediaColumns.DATA };
        Cursor cursor = context.getContentResolver().query(uri, projection,
                null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int column_index = cursor
                    .getColumnIndex(MediaStore.MediaColumns.DATA);
            path = cursor.getString(column_index);
        }
        if (cursor != null) {
            cursor.close();
        }
        return path;
    }

}

Related Tutorials