android 选择图片后获取真实的图片路径

private String getRealImageFilePath(final Context context, final Uri uri) {
        String mRealPath = "";
        String[] filePathColumn = {MediaStore.Images.Media.DATA};
        Cursor cursor = context.getContentResolver().query(uri, filePathColumn, null, null, null);
        if  (cursor != null && !cursor.isClosed()) {
            if (cursor.getCount() > 0 && cursor.moveToFirst()) {
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                if (columnIndex > -1) {
                    mRealPath = cursor.getString(columnIndex);
                }

                if (!cursor.isClosed()) {
                    cursor.close();
                }

                return mRealPath;
            }
        }
        return "";
    }

你可能感兴趣的:(android 选择图片后获取真实的图片路径)