Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

honoring rotation lock in android

Tags:

java

android

I am trying to honor the android rotation lock setting - I want my app to display in whatever orientation the home screen is locked in. I found the following knobs:

  1. Settings.System.ACCELEROMETER_ROTATION - determine if the screen orientation is locked.
  2. Display.getRotation() - determine if the device is rotated from it's "natural" orientation, which may be portrait or landscape.
  3. Display.getWidth()/getHeight() - determine the current orientation of the device.

I thought this would be simple to do, but I can't seem to find the right combination of the above to get this to work. The reported values seem inconsistent, especially during app startup (is onResume the right place to check these values?).

Note I don't want to simply always fix the orientation of my activity to portrait or landscape, I want to set it to the orientation the user has locked the screen in. For tablets this could be landscape or portrait. If the user sets the Auto-Rotate setting, I want my activity to operate in sensor mode.

like image 936
slushi Avatar asked Dec 14 '11 18:12

slushi


People also ask

How do I unlock rotation lock?

Swipe up from the bottom edge of your screen to open Contol Center. Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone or iPod touch sideways.


1 Answers

after hours of debugging, it appears the answer is as simple as checking if rotation is locked and if so, calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR). Now excuse me while I go step off the nearest bridge...

like image 122
slushi Avatar answered Oct 12 '22 04:10

slushi