Control default auto rotate screen in my application

后端 未结 4 524
我在风中等你
我在风中等你 2020-12-09 07:14

I have a toggle button in my application. I want to change or control default setting, Auto rotate screen(Settings>Display>Auto rotate screen) programmatically. Does anybody

4条回答
  •  情深已故
    2020-12-09 07:45

    Have you tried this in your Activity?

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    
    //This is the default value
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    

    After that you can use this to disable the auto orientation:

    public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled)
    {
      Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
    }
    

    Documentation

提交回复
热议问题