# Screen orientation not changing when rotating Android device

**URL:** <https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676>\
**Category:** SDL Development\
**Created:** [October 4, 2019, 3:04pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676 "2019-10-04T15:04:27Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![artsoft](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/artsoft/32/3873_2.png) [@artsoft](https://discourse.libsdl.org/u/artsoft)\
**Post date:** [October 4, 2019, 3:04pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/1 "2019-10-04T15:04:27Z")

</div>

I’m currently using SDL2 version 2.0.5 for the Android port of my game, which works just fine, but I would like to upgrade to a newer SDL version.

However, I have the problem that automatic screen rotation does not work anymore when using a newer version of SDL2. It still rotates 180° from landscape mode to flipped landscape mode when turning the device by 180°, but it refuses to rotate from landscape to portrait mode or from portrait to landscape mode, but just stays in whatever orientation the game was started with (either landscape or portrait mode).

I’ve encountered this problem when using SDL2 versions 2.0.6 or 2.0.8 (newer versions 2.0.9 and 2.0.10 unfortunately refuse to compile on my development system).

I have tested (and reproduced) this odd behavior on Android 4.4 and Android 9.

I have the suspicion that it may have something to do with my “AndroidManifest.xml” file, but haven’t found a solution so far.

Any idea what might go wrong here?

Here’s my “AndroidManifest.xml” file:

```
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.artsoft.rocksndiamonds"
      android:versionCode="4010301"
      android:versionName="4.1.3.1"
      android:installLocation="auto">

    <application android:label="@string/app_name"
                 android:icon="@drawable/ic_launcher"
                 android:allowBackup="true"
                 android:debuggable="true"
                 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                 android:hardwareAccelerated="true">
        <activity android:name="RocksNDiamonds"
                  android:configChanges="keyboardHidden|orientation|screenSize"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <!-- Android 2.3.3 (min) / Android 4.2.2 (target) -->
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />

    <!-- OpenGL ES 2.0 -->
    <uses-feature android:glEsVersion="0x00020000" /> 

    <!-- Allow writing to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Allow doing network operations -->
    <uses-permission android:name="android.permission.INTERNET" /> 
</manifest> 

```

Any hint or help would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Becker](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@Sylvain\_Becker](https://discourse.libsdl.org/u/Sylvain_Becker)\
**Post date:** [October 22, 2019, 7:06am UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/2 "2019-10-22T07:06:55Z")

</div>

> [@artsoft](#):
>
> I’ve encountered this problem when using SDL2 versions 2.0.6 or 2.0.8 (newer versions 2.0.9 and 2.0.10 unfortunately refuse to compile on my development system).

I think you should try to solve this first ! try to fix compiling latest hg source.

---

<div class="post-metadata">

**Author:** ![artsoft](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/artsoft/32/3873_2.png) [@artsoft](https://discourse.libsdl.org/u/artsoft)\
**Post date:** [November 13, 2019, 12:58pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/3 "2019-11-13T12:58:39Z")

</div>

I think you are right. It’s always best to do such tests with the latest SDL versions (both stable and from the repository).

So I’ll try again to compile the latest SDL code, and see if that helps…

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [November 13, 2019, 1:14pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/4 "2019-11-13T13:14:15Z")

</div>

Check out my tutorial how to build the latest SDL with android studio.  
[https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10)

Regarding the screen orientation . Try adding the screenOrientation under activity:

```auto
<activity android:name="RocksNDiamonds"
                  android:configChanges="keyboardHidden|orientation|screenSize"
                  android:label="@string/app_name"
                  android:screenOrientation="sensorLandscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

```

Read more about it here: [https://developer.android.com/guide/topics/manifest/activity-element#screen](https://developer.android.com/guide/topics/manifest/activity-element#screen)

Another note: Do you really need the:

```auto
<!-- Allow writing to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

```

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [January 8, 2020, 11:02pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/5 "2020-01-08T23:02:33Z")

</div>

> [@artsoft](#):
>
> I’m currently using SDL2 version 2.0.5 for the Android port of my game, which works just fine, but I would like to upgrade to a newer SDL version. However, I have the problem that automatic screen rotation does not work anymore when using a newer version of SDL2

Did you ever resolve this? I am experiencing the identical issue: currently using SDL 2.0.5 and rotations between landscape and portrait are working. Trying to update to SDL 2.0.10 and only 180-degree rotations are working, my app is stuck in portrait (or reverse portrait) orientation.

Of course I can’t be sure whether it’s the changes in SDL which are responsible or the different Android API level, but I need both portrait and landscape orientations to work.

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [January 8, 2020, 11:56pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/6 "2020-01-08T23:56:49Z")

</div>

> [@rtrussell](#):
>
> Of course I can’t be sure whether it’s the changes in SDL which are responsible or the different Android API level, but I need both portrait and landscape orientations to work.

Checking at Bugzilla I see there’s a [bug](https://bugzilla.libsdl.org/show_bug.cgi?id=4246) which may be related to this issue. It’s well over a year old and shown as WAITING, what’s the status of this please?

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [January 16, 2020, 4:37pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/7 "2020-01-16T16:37:50Z")

</div>

> [@rtrussell](#):
>
> Checking at Bugzilla I see there’s a [bug](https://bugzilla.libsdl.org/show_bug.cgi?id=4246) which may be related to this issue

Just to tie up loose ends, it was this bug. I’ve applied the suggested patch and rotation now works again; I hope this can be fixed properly in the next release of SDL2.

---

<div class="post-metadata">

**Author:** ![artsoft](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/artsoft/32/3873_2.png) [@artsoft](https://discourse.libsdl.org/u/artsoft)\
**Post date:** [January 16, 2020, 11:56pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/8 "2020-01-16T23:56:03Z")

</div>

@DaSkuggo : Thank you for your reply! I’ve tried adding “screenOrientation” with various values (like “fullSensor”), but it does not change anything at all! ☹

Regarding the permissions: I am not sure if I really need it; what I want to do is write to the application-specific directories as returned by “SDL\_AndroidGetExternalStoragePath()”, depending on “SDL\_AndroidGetExternalStorageState()” returning bitmask “SDL\_ANDROID\_EXTERNAL\_STORAGE\_WRITE” set. Apparently it depends on the API level; also see: [https://developer.android.com/reference/android/Manifest.permission.html#WRITE\_EXTERNAL\_STORAGE](https://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE)

@rtrussell : Thanks a lot for your comments – apparently I am not the only one who encountered this problem (and apparently it is not the fault of my build system)! 🙂

I will try out this patch soon – which of them did you finally use? If I understand it right, not all of the suggested patches do the “right thing”?! 🤔

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [January 17, 2020, 9:51am UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/9 "2020-01-17T09:51:36Z")

</div>

> [@artsoft](#):
>
> I will try out this patch soon – which of them did you finally use? If I understand it right, not all of the suggested patches do the “right thing”?!

I used Sylvain’s patch because I want the ‘full sensor’ mode of operation. But since I’m not using the [SDL\_HINT\_ORIENTATIONS](https://wiki.libsdl.org/SDL_HINT_ORIENTATIONS) hint I didn’t really need to apply the full patch at all, I could simply have replaced the code with:

`mSingleton.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);`

---

<div class="post-metadata">

**Author:** ![artsoft](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/artsoft/32/3873_2.png) [@artsoft](https://discourse.libsdl.org/u/artsoft)\
**Post date:** [August 29, 2020, 10:25pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/10 "2020-08-29T22:25:46Z")

</div>

Sorry for the late reply. Took me quite some time to change my build system for the Android platform from ant to gradle, to finally be able to use the current SDL 2.0.12 for resolving this issue.

And the problem was still there with latest SDL 2.0.12 then.

But I finally found out what caused that problem: Somewhere between SDL 2.0.5 and 2.0.12, using the flag SDL\_WINDOW\_RESIZABLE when creating the SDL surface was required for working screen orientation changes on Android (together with the appropriate settings in the manifest file), even when using fullscreen mode!

So once I added SDL\_WINDOW\_RESIZABLE, everything was fine!

Maybe this could help somebody else using old SDL code and facing similar problems.

---

<div class="post-metadata">

**Author:** ![eri0o](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/eri0o/32/4277_2.png) [@eri0o](https://discourse.libsdl.org/u/eri0o)\
**Post date:** [January 22, 2021, 3:55pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/11 "2021-01-22T15:55:53Z")

</div>

Hey, does anyone knows if screen rotation hints also work on Android or are limited to iOS as stated in the documentation?

> **[SDL\_HINT\_ORIENTATIONS - SDL Wiki'](https://wiki.libsdl.org/SDL_HINT_ORIENTATIONS)**

I ask because there’s a draft label on top in the docs and I don’t know what that means.

---

<div class="post-metadata">

**Author:** ![eri0o](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/eri0o/32/4277_2.png) [@eri0o](https://discourse.libsdl.org/u/eri0o)\
**Post date:** [January 24, 2021, 11:50am UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/12 "2021-01-24T11:50:01Z")

</div>

I read the Android source code and used them and they apparently work, just need to update the docs.

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [January 24, 2021, 12:17pm UTC](https://discourse.libsdl.org/t/screen-orientation-not-changing-when-rotating-android-device/26676/13 "2021-01-24T12:17:12Z")

</div>

> [@eri0o](#):
>
> just need to update the docs

Sigh. On a quick scan of the [What’s New](https://www.libsdl.org/tmp/SDL/WhatsNew.txt) list it looks as though the official online SDL2 [documentation](https://wiki.libsdl.org/) corresponds, roughly, to SDL 2.0.6. None of the functions added since are included, as far as I can see.
