get Intent MediaStore Image Path - Android Media

Android examples for Media:Picture

Description

get Intent MediaStore Image Path

Demo Code

/* //w  ww  .ja  v a2 s.co 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.
 */
import java.util.ArrayList;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class Main{
    
    public static String getIntentImagePath(ContentResolver cr, Uri uri) {
        // ?Data? 1: 2:Uri Uri
        String u = MediaStoreHelper.getImagePath(cr, uri);
        if (u != null) {
            if (FileHelper.fileExists(u)) {
                return u;
            }
        }
        return uri.getPath();
    }
    
    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