HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaCritical

Check orientation on Android phone

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
checkphoneandroidorientation

Problem

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

Solution

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.

Code Snippets

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

Context

Stack Overflow Q#2795833, score: 768

Revisions (0)

No revisions yet.