How can I check if the Android phone is in Landscape or Portrait?
Some time has passed since most of these answers have been posted and some use now deprecated methods and constants.
I've updated Jarek's code to not use these methods and constants anymore:
protected int getScreenOrientation()
{
Display getOrient = getWindowManager().getDefaultDisplay();
Point size = new Point();
getOrient.getSize(size);
int orientation;
if (size.x < size.y)
{
orientation = Configuration.ORIENTATION_PORTRAIT;
}
else
{
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
return orientation;
}
Note that the mode Configuration.ORIENTATION_SQUARE
isn't supported anymore.
I found this to be reliable on all devices I've tested it on in contrast to the method suggesting the usage of getResources().getConfiguration().orientation