Check orientation on Android phone

Mohit Deshpande picture Mohit Deshpande · May 9, 2010 · Viewed 275.6k times · Source

How can I check if the Android phone is in Landscape or Portrait?

Answer

hackbod picture hackbod · May 9, 2010

The current configuration, as used to determine which resources to retrieve, is available from the Resources' Configuration object:

getResources().getConfiguration().orientation;

You can check for orientation by looking at its value:

int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
    // In landscape
} else {
    // In portrait
}

More information can be found in the Android Developer.