How to get the screen mode (portrait/landscape) from an application? I have find no method about this in class Activity/View. Thanks.
Asked
Active
Viewed 784 times
0
-
Duplicate of http://stackoverflow.com/questions/3589503/android-getting-orienation-landscape-portrait-on-activity-launch – Femi Sep 19 '11 at 04:46
2 Answers
0
This should work, which uses the new getRotation instead of the deprecated getOrientation(). http://developer.android.com/reference/android/view/Display.html#getRotation()
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
display.getRotation();

JoeLallouz
- 1,338
- 1
- 10
- 14
-
@Femi, the answer in that thread refers to a deprecated API method and is no longer the appropriate solution. – JoeLallouz Sep 19 '11 at 04:55
0
Display mDisplay= activity.getWindowManager().getDefaultDisplay();
int width= mDisplay.getWidth();
int Height= mDisplay.getHeight();
if(width>height)
{
//Landscape
}
else
{
//portrait
}

Mohammed Azharuddin Shaikh
- 41,633
- 14
- 96
- 115
-
As per [hackbod's explanation](http://stackoverflow.com/questions/2795833/check-orientation-on-android-phone/2795935#2795935) this answer is not correct. `getResources().getConfiguration().orientation` is the only recommended way. – Reno Sep 19 '11 at 06:14