enable screen rotation android
15,222
Solution 1
You can use this
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
See the official documentation for more details
Solution 2
put this line in manifest
android:configChanges="orientation"
and use this code as per your requirement
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
and also put this to enable
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);
Solution 3
Check out also that you don't have this line in your manifest file for your activity:
android:screenOrientation="portrait"
That will disable the rotate of the screen.
Solution 4
This setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);
is incorrect
If you want to enable rotation again you have to use:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Author by
Paulius Vindzigelskis
Updated on June 04, 2022Comments
-
Paulius Vindzigelskis almost 2 years
I have disabled screen rotation in one activity in particular time. Now I need that particular time it will be enabled. How can I enable rotation, when i disabled it using this: ?