Android URI to Path Convert getRealPathFromURI(Activity activity, Uri contentUri)

Here you can find the source of getRealPathFromURI(Activity activity, Uri contentUri)

Description

get Real Path From URI

Declaration

public static String getRealPathFromURI(Activity activity,
            Uri contentUri) 

Method Source Code

//package com.java2s;
import android.app.Activity;
import android.database.Cursor;

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

public class Main {
    public static String getRealPathFromURI(Activity activity,
            Uri contentUri) {/*from w w w.  ja v a 2 s .c  o  m*/
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.managedQuery(contentUri, proj, null, null,
                null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.moveToFirst()) {
            return cursor.getString(column_index);
        } else {
            return null;
        }
    }
}

Related

  1. getRealPathFromURI(Activity activity, Uri contentUri)