Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.DisplayMetrics; import android.view.WindowManager; public class Main { public static final int PORTRAIT = 1; public static final int LANDSCAPE = 2; public static int getOrientation(Context context) { DisplayMetrics displayMetrics = new DisplayMetrics(); displayMetrics.widthPixels = 1280; displayMetrics.heightPixels = 720; try { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(displayMetrics); } catch (Exception e) { //do nothing } if (displayMetrics.heightPixels > displayMetrics.widthPixels) { return PORTRAIT; } else { return LANDSCAPE; } } }