get Device Current Orientation - Android User Interface

Android examples for User Interface:Screen Orientation

Description

get Device Current Orientation

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.res.Configuration;

public class Main {
    public static int getDeviceCurrentOrientation(Context context) {
        int orientation = context.getResources().getConfiguration().orientation;
        if (orientation != Configuration.ORIENTATION_LANDSCAPE
                && orientation != Configuration.ORIENTATION_PORTRAIT) {
            return Configuration.ORIENTATION_UNDEFINED;
        }// w ww . j a v a 2s . c  om
        return orientation;
    }
}

Related Tutorials