Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

orientation lock in android programmatically

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.

like image 791
user2682527 Avatar asked Mar 24 '26 11:03

user2682527


1 Answers

Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);


Locks the screen (activity) in whatever the orientation it was.

Requires API Level >= 18

like image 121
Junaid Avatar answered Mar 26 '26 01:03

Junaid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!