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.
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"?
I know of getRotation(), as described here: how to detect orientation of android device?
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.
How can I find out which way the device is turned, so I can temporarily fix the device to that orientation?
UPDATE
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.
But here's the problem. It wasn't until Gingerbread (2.3, API 9) that REVERSE landscape and reverse portrait were added.
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.
I didn't realize this was more difficult in Froyo, so I will rephrase the question I spelled out before:
In Froyo, how can I detect whether the device is in landscape, reverse landscape, portrait or reverse portrait?
The suggestions listed all work--for Gingerbread or higher.