Android Image Orientation Get getOriginalFilePath(Context context, Uri imageUri)

Here you can find the source of getOriginalFilePath(Context context, Uri imageUri)

Description

Gets the original file path.

License

Open Source License

Parameter

Parameter Description
context the context
imageUri the image uri

Return

the original file path

Declaration

public static String getOriginalFilePath(Context context, Uri imageUri) 

Method Source Code

//package com.java2s;

import android.content.Context;
import android.database.Cursor;

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

public class Main {
    /**/*from w w  w .j a  v a 2 s .co  m*/
     * Gets the original file path.
     * 
     * @param context
     *            the context
     * @param imageUri
     *            the image uri
     * @return the original file path
     */
    public static String getOriginalFilePath(Context context, Uri imageUri) {
        if (imageUri.getScheme().equals("file")) {
            return imageUri.getPath();
        }
        String[] filePathColumn = { MediaColumns.DATA, MediaColumns.DATA };
        Cursor cursor = context.getContentResolver().query(imageUri,
                filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        return cursor.getString(columnIndex);
    }
}

Related

  1. getOrientation(Context context, Uri imageUri)