10

I have an activity that open from browser when Device is in Landscape get me below error

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

Manifest

<activity android:name=".Activity.MyActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.Theme_Slide"
        >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="xxx"
                android:scheme="xxx" />
            <data
                android:host="xxx"
                android:scheme="xxx" />
        </intent-filter>
    </activity>

style.xml

<style name="AppTheme.Theme_Slide" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowCloseOnTouchOutside">false</item>
</style>

UPDATE FIND SOLUTION

In android Oreo (API 26) you can not change orientation for Activity that have below line in style

 <item name="android:windowIsTranslucent">true</item>

You have two way for solving this :

1) You can simply remove above line (or turn it to false) and your app works fine.

2) Or you can first remove below line from manifest for that activity

android:screenOrientation="portrait"

Then you must add this line to java file

    //android O fix bug orientation
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
Radesh
  • 13,084
  • 4
  • 51
  • 64

0 Answers0