Android – Detect The Phone Orientation

android.view.Display class provide a simple way to determine the phone orientation.

// Get display for detecting the phone orientation
display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

// Get the orientation
int orientation = display.getOrientation(); 

For my HTC Tattoo, i get
When the phone is vertical
orientation = 0

When the phone rotates 90 degrees in clockwise direction
orientation = 0

When the phone is inverted
orientation = 0

When the phone rotates 90 degrees in anti-clockwise direction

orientation = 1

Although the above method is simple, it can only detect 90 degrees anti-clockwise rotation.

Done =)

Reference: Android Snippets – Get Size and Orientation of the Screen

2 thoughts on “Android – Detect The Phone Orientation”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.