3

When I upgraded compileSdkVersion 26 & targetSdkVersion 26 to compileSdkVersion 27 & targetSdkVersion 27 in my build.gradle (Module: app) file respectively, it works fine with all other android versions but I encounter the following error in Android 8.0 (API level 26) emulator:

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

Removing android:screenOrientation="portrait" worked for me but now my screen is rotating (which I don't want to).

Switching back to compileSdkVersion 26 again works both ways that is I don't get any error and activity screen is also restricted to portrait only.

But my question is to restrict screen orientation to portrait mode only in Android 8.0 (API level 26) while targeting Android Android 8.1 (API level 27).

Any help will be highly appreciated. Thanks.!

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40
  • 1
    https://stackoverflow.com/questions/46980697/lock-screen-orientation-when-targeting-android-api-27-with-a-non-opaque-activity – Goku Jan 03 '18 at 06:27
  • Check this: https://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only – Fenil Patel Jan 03 '18 at 06:30
  • i solved it in my project like this https://stackoverflow.com/a/48077046/4149649 – Yuri Misyac Jan 03 '18 at 12:08
  • Its Worked for me ,If u place the DialogTheme to activity remove the set orientation from the activity tag which is from manifesto , It will take the Orientation from the previous activity If you don't have that theme no need to remove setorientation from Manifesto.. and for below Versions place this on oncreate if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } – VV W Jun 22 '18 at 05:03

0 Answers0