Here you can find the source of getExifOrientation(ContentResolver cr, Uri uri)
public static int getExifOrientation(ContentResolver cr, Uri uri)
//package com.java2s; import java.io.IOException; import android.content.ContentResolver; import android.database.Cursor; import android.media.ExifInterface; import android.net.Uri; import android.provider.MediaStore.Images; import android.util.Log; public class Main { private static final String TAG = "Util"; public static int getExifOrientation(ContentResolver cr, Uri uri) { int degree = 0; if (uri.getScheme().equals("content")) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = cr.query(uri, projection, null, null, null); if (c.moveToFirst()) { degree = c.getInt(0);// ww w . j av a2s . c o m } } else if (uri.getScheme().equals("file")) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int orientation = exif.getAttributeInt( ExifInterface.TAG_ORIENTATION, -1); if (orientation != -1) { // We only recognize a subset of orientation tag values. switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; } } } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return degree; } public static boolean equals(String a, String b) { // return true if both string are null or the content equals return a == b || a.equals(b); } }