Android honorary rotation lock

I am trying to comply with Android rotation lock setting. I want my application to be displayed in any orientation on which the home screen is locked. I found the following buttons:

  • Settings.System.ACCELEROMETER_ROTATION - determine if the screen orientation is locked.
  • Display.getRotation () - determines whether the device rotates from it in a "natural" orientation, which can be portrait or landscape.
  • Display.getWidth () / getHeight () - determines the current orientation of the device.

I thought it would be easy to do, but I cannot find the right combination of the above to make it work. The values ​​presented seem inconsistent, especially during application startup (onResume the right place to check these values?).

Note. I don’t want to just always fix the orientation of my activity on portrait or landscape orientation, I want to configure it for the orientation in which the user locked the screen. For tablets, it can be a landscape or a portrait. If the user sets the auto-rotation setting, I want my activity to work in sensor mode.

+5
source share
1 answer

after hours of debugging, it seems like the answer is as simple as checking for rotation blocking, and if so, calling setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_NOSENSOR). Now excuse me while I get off the nearest bridge ...

+3
source

All Articles