Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.database.Cursor; import android.media.ExifInterface; import android.net.Uri; import android.provider.MediaStore; public class Main { private static final int ORIENTATION_90 = 90; private static final int ORIENTATION_180 = 180; private static final int ORIENTATION_270 = 270; /** * Get Image orientation from uri * * @param context Context of image * @param photoUri Uri of image * @return */ public static int getOrientation(Context context, Uri photoUri) { Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); try { if (cursor.moveToFirst()) { if (cursor.getInt(0) == ORIENTATION_270) return ExifInterface.ORIENTATION_ROTATE_270; else if (cursor.getInt(0) == ORIENTATION_180) return ExifInterface.ORIENTATION_ROTATE_180; else if (cursor.getInt(0) == ORIENTATION_90) return ExifInterface.ORIENTATION_ROTATE_90; } } finally { cursor.close(); } return -1; } }