How to detect exact orientation of device in Froyo?
<p>I'm trying to temporarily lock the orientation of the Android device, where most of the time it changes with the sensor. So what I want to do is figure out what the current orientation (landscape, reverse landscape, portrait, reverse portrait) is, change the orientation to that one orientation, and then later change it back to what it was originally.</p>

<p>I am aware that I can use code such as
    int orientation = this.getResources().getConfiguration().orientation;
    this.setRequestedOrientation(orientation);
The problem with this is that typically the orientation in question is set as "undefined" or perhaps "user" or "sensor," which doesn't help me. How can I find out which of the four possible sides of the screen is "down"?</p>

<p>I know of getRotation(), as described here: <a href="http://stackoverflow.com/questions/5112118/how-to-detect-orientation-of-android-device">how to detect orientation of android device?</a></p>

<p>The problem with that is that I can find out the actual rotation (0, 90, 180, 270 degrees) from the device's "natural" orientation... but that doesn't help me if I don't know what the original orientation is.</p>

<p>How can I find out which way the device is turned, so I can temporarily fix the device to that orientation?</p>

<h1>UPDATE</h1>

<p>No, this is not a duplicate question.
I suspect there may be different behavior on different devices, but can't be certain of that.
I did more experimentation and research. I had thought for some reason that getConfiguration().orientation returned "unspecified". I was mistaken. It does return Landscape or Portrait.</p>

<p>But here's the problem. It wasn't until Gingerbread (2.3, API 9) that REVERSE landscape and reverse portrait were added.</p>

<p>So if the device is in reverse landscape mode, for example, getConfiguration.orientation would tell me that it's in landscape mode. Then when I set the requested orientation to landscape--bam, the screen flips upside down.</p>

<p>I didn't realize this was more difficult in Froyo, so I will rephrase the question I spelled out before:</p>

<p>In Froyo, how can I detect whether the device is in landscape, reverse landscape, portrait or reverse portrait?</p>

<p>The suggestions listed all work--for Gingerbread or higher.</p>
