1

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.

Zelig
  • 187
  • 3
  • 8

4 Answers4

1

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.

Community
  • 1
  • 1
Peter O.
  • 32,158
  • 14
  • 82
  • 96
0

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();
slayton
  • 20,123
  • 10
  • 60
  • 89
0

Use getRotation()

Gallal
  • 4,267
  • 6
  • 38
  • 61
0

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.

Community
  • 1
  • 1
FloppyDisk
  • 1,693
  • 16
  • 25