Set the screen autorotation system setting from the code

I am trying to figure out how to change this setting programmatically. Can anyone point out an API or suggest something?

Images show where this option is in Android:

enter image description hereenter image description here

+4
source share
2 answers

Mark this link

http://developer.android.com/reference/android/provider/Settings.System.html#ACCELEROMETER_ROTATION

And here is the code for you

android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.ACCELEROMETER_ROTATION,1); 

And this permission is required in the manifest

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

+4
source

If what you are trying to do is lock your application in a specific screen orientation, you can use the android:screenOrientation in the activity manifest.

See here .

-1
source

Source: https://habr.com/ru/post/1440545/


All Articles