orientation lock in android programmatically

android, java, screen-orientation

Solution

Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

Locks the screen (activity) in whatever the orientation it was. Requires API Level >= 18

Problem

I have the following code. Java ``` public void lockScreenOrientation() { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); } public void unlockScreenOrientation() { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } ``` I am calling these functions from javascript. Control is entering these methods. However the orientation is not locked. I have tried following to lock the orientation ``` setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); ``` None of these seem to work. Any pointers would be helpful.

Original source

Related problems