Search code examples
androidaccelerometer

How do I determine if an android device is naturally landscape or portrait?


How do I determine whether or not the accelerometer would report a roll of zero when the bottom long side of the screen is facing the ground?

I need to do this without instructing the user to hold the phone in a certain position. I am hoping to be able to do something like:

Context.getResources().getConfiguration().getNaturalOrientation == Orientation.LANDSCAPE

IMPORTANT: The above line of code is not possible, it's just an example of what I would like to do.


Solution

  • I found the answer for this. It's very simple using API8 and higher, simply use Display.getRotation()