Public Int getDeviceDefaultOrientation() {
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Configuration config = getResources().getConfiguration();
Int Rotation = windowManager.getDefaultDisplay().getRotation();
If ( ((Rotation == Surface.ROTATION_0 || Rotation == Surface.ROTATION_180) &&
config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|| ((Rotation == Surface.ROTATION_90 || Rotation == Surface.ROTATION_270) &&
config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
Return Configuration.ORIENTATION_LANDSCAPE;
} Else {
Return Configuration.ORIENTATION_PORTRAIT;
}
}