Zelig
Zelig

Reputation: 1808

Getting the actual orientation of the phone

I need to determine the actual orientation of the phone which is running my app and I can't find any way to do it. I have found the "getRequestedOrientation" function but it only retrieves the orientation set by the "setRequestedOrientation" function.

In my app, I let the phone choose the orientation according to it's physical orientation. And I have some customizing to do depending on the result.

How can I do?

Thanks in advance for the time you will spend trying to help me.

Upvotes: 1

Views: 561

Answers (4)

Peter O.
Peter O.

Reputation: 32878

According to these two questions:

you can use:

Activity.getResources().getConfiguration().orientation

According to the comment on the second question, however, this value returns only landscape or portrait. If you need reverse orientation as well, I would suggest querying the accelerometer values to detect the difference. However, I'm not familiar with Android and accelerometers enough to suggest how to do so exactly.

Upvotes: 1

FloppyDisk
FloppyDisk

Reputation: 1703

See this, this, and this stackoverflow question. They all address how to get the Android phone orientation and the second one includes a detailed explanation of how the Android compass and orientation system works.

Upvotes: 0

Gallal
Gallal

Reputation: 4262

Use getRotation()

Upvotes: 0

slayton
slayton

Reputation: 20319

Its really to get the current orientation.

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int orientation = display.getOrientation();

Upvotes: 0

Related Questions