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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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