get MediaStore Image Path - Android Media

Android examples for Media:Picture

Description

get MediaStore Image Path

Demo Code

/* //from w ww  .  j  a v  a 2s  .c o m
 * @Title: MediaStoreHelper.java
 * Created by liubingsr on 2012-6-19 ????6:17:57 
 * Copyright (c) 2012 Zhima Information Technology Co., Ltd. All rights reserved.
 */
//package com.java2s;

import android.content.ContentResolver;

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

public class Main {

    public static String getImagePath(ContentResolver cr, Uri uri) {
        String result = null;
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cur = cr.query(uri, projection, null, null, null);
        if (cur != null) {
            int columnIndex = cur
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cur.moveToFirst();
            result = cur.getString(columnIndex);
            cur.close();
        }
        return result;
    }
}

Related Tutorials