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.
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.
Checking at Bugzilla I see there’s a bug 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?
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.
@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
@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”?!
I used Sylvain’s patch because I want the ‘full sensor’ mode of operation. But since I’m not using the SDL_HINT_ORIENTATIONS hint I didn’t really need to apply the full patch at all, I could simply have replaced the code with:
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.
Sigh. On a quick scan of the What’s New list it looks as though the official online SDL2 documentation corresponds, roughly, to SDL 2.0.6. None of the functions added since are included, as far as I can see.