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.
Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
Locks the screen (activity) in whatever the orientation it was.
Requires API Level >= 18
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