Friday, December 24, 2010

Finding Android screen orientation

There are multiple way to get Android screen orientation (landscape/portrait), however some of them are problematic:
this.getWindowManager().getDefaultDisplay().getOrientation()
Is depricated

this.getWindowManager().getDefaultDisplay().getRotation()
Works only from Android 2.2

I Found this to be the best resource until now, since it's exists since API 1 & it's not deprecated, yet:
this.getResources().getConfiguration().orientation

Compare it with:
Configuration.ORIENTATION_LANDSCAPE
Configuration.ORIENTATION_PORTRAIT
Configuration.ORIENTATION_SQUARE

No comments: