java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

前端 未结 30 1706
难免孤独
难免孤独 2020-12-02 04:43

I am facing the problem while retrieving the contacts from the contact book in Android 8.0 Oreo java.lang.IllegalStateException: Only fullscreen opaque activities can reques

30条回答
  •  清歌不尽
    2020-12-02 05:24

    Just Set Orientation of activity in Manifiest.xml

    android:screenOrientation="unspecified"
    

    OR for restricted to Portrait Orientation

    You can also use in Activity, In onCreate method call before super.onCreate(...) e.g.

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            setOrientation(this);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.your_xml_layout);
            //...
            //...
    }
    
    // Method 
    public static void setOrientation(Activity context) {
       if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.O)
            context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
          else
            context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    

提交回复
热议问题