Here you can find the source of getCameraRotation(final Context context)
public static int getCameraRotation(final Context context)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; import android.view.Surface; import android.view.WindowManager; public class Main { public static int getCameraRotation(final Context context) { final WindowManager windowManager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); int rotation = windowManager.getDefaultDisplay().getRotation(); final DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); final int width = metrics.widthPixels; final int height = metrics.heightPixels; if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) { // Need to rotate on portrait device rotation = 270 - rotation;/* ww w. jav a 2 s . c o m*/ } return rotation; } }