Find out if Android device is portrait or landscape for normal usage?

joynes picture joynes · Sep 9, 2010 · Viewed 43.8k times · Source

Is there anyway to find out if a device is portrait or landscape by default? In that I mean how you normally use the device.

Most phones have a portrait screen for normal usage but is there some flag for finding that out?

Answer

Hazem Farahat picture Hazem Farahat · May 21, 2011

You can do this by:

For Lanscape

if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
    //Do some stuff
}

For Portrait

if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
    //Do some stuff
}

Check: http://developer.android.com/reference/android/content/res/Configuration.html#orientation