getRotation
always returns zero regardless which way the screen is oriented. I'm running this on a real device running 2.3. Any reason why?
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
getRotation will only work if the app has a UI and the UI is allowed to rotate. There is a setting for the operating system that can prevent any app from automatically rotating:
Settings > Display > Auto-rotate Screen
This has to be enabled. On my device it was disabled. Nevertheless, the Android docs on getRotation not only fail to point this out but even give you the assumption that getRotation will return the rotation even without a UI. You need a UI. This of course is a problem for something like a service that has no UI but needs to know the orientation of the device for purposes that have nothing to do with user interaction. Personally, I get continuously pissed by Google for hiring amateur programmers who think that accessing hardware features should almost always require some kind of UI. This kind of problem has popped up on many occassions, like having to have a SurfaceView to record a video.
Finally, the getRotation is clearly not required by an app to figure out whether the device is rotated 0, 90, 180 or 270 degrees. With Auto-Rotate Screen turned off, the default camera app is still able to figure out the angular rotation, so it cannot be from getRotation, unless it is somehow capable of turning on the Auto-Rotate Screen setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With