AndroidManifest and Respecting User Orientation?

How does one disable Sensor Autorotation and have the device respect the user’s desired orientation? Currently my app autorotates and disregards the user rotation preference/lock. I’ve tried editing the AndroidManifest.xml using custom templates and it doesn’t seem to affect the autorotation. In fact, it doesn’t seem to do anything. I’ve tried all values. Right now I temporarily set it to portrait and it still rotates. This is what I have:

project.xml
<template if="android" path="templates/android/AndroidManifest.xml" rename="app/src/main/AndroidManifest.xml" />

AndroidManifest.xml
<activity android:name="MainActivity" android:launchMode="singleTask" android:label="Test" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout" android:screenOrientation="portrait">

I checked the generated AndroidManifest and it seems to be copying my custom template as is. Also, I’m getting mixed results from my AndroidManifest. For example, changing the app version number in the Manifest directly doesn’t change anything, and it still follows the value in the project.xml. But changing application android:label for example works. What could I be doing incorrectly?

1 Like

A little update, I tried using Android SDK Tools’ apkanalyzer to see if the resulting apk reflected the screenOrientation changes to the AndroidManifest.

Setting to all the possible values of android:screenOrientation resulted in the following:

  • unspecified – android:screenOrientation="-1"
  • behind – android:screenOrientation=“3”
  • landscape – android:screenOrienation=“0”
  • portrait – android:screenOrientation=“1”
  • reverseLandscape – android:screenOrientation=“8”
  • reversePortrait – android:screenOrientation=“9”
  • sensorLandscape – android:screenOrientation=“6”
  • sensorPortrait – android:screenOrientation=“7”
  • userLandscape – android:screenOrientation=“11”
  • userPortrait – android:screenOrientation=“12”
  • sensor – android:screenOrientation=“4”
  • fullSensor – android:screenOrientation=“10”
  • nosensor – android:screenOrientation=“5”
  • user – android:screenOrientation=“2”
  • fullUser – android:screenOrientation=“13”
  • locked – android:screenOrientation=“14”

It appears the AndroidManifest is in fact applying the changes but none of the values result in locking the orientation or respecting the user orientation preference. Setting to an orientation launches the app in the expected orienation but ignores the lock and autorotates to portrait.

If it helps any, additional info:

<uses-sdk android:minSdkVersion="16" 
		  android:targetSdkVersion="28"/>
  • openfl 9.0.2
  • haxe 4.1.4
  • lime 7.8.0
    Any ideas?

Maybe this will help.

1 Like

So far seems to work after plugging it in my AndroidManifest. I’ll try experimenting with it. Thanks!

So I did some tests and it seems it’s still not working as I expected.

For starters, I thought I would have full control of the orientation using screenOrientation. The project.xml window orientation seems to override these settings.

Here are my results, tested with PiratePig

With project.xml window orientation removed (defaults to auto):

screenOrientation: portrait
Expected Result: Fixed Portrait
Result: Sensor that starts with Portrait (doesn’t respect lock)

screenOrientation: landscape
Expected Result: Fixed Landscape
Result: Sensor that starts with Landscape (doesn’t respect lock)

screenOrientation: sensorPortrait
Expected Result: Portrait or Reverse Portrait (doesn’t respect lock)
Result: Sensor that starts with Portrait (doesn’t respect lock)

screenOrientation: sensorLandscape
Expected Result: Landscape or Reverse Landscape (doesn’t respect lock)
Result: Sensor that starts with Landscape (doesn’t respect lock)

screenOrientation: user
Expected Result: User’s preferred orientation
Result: Sensor that starts with User Orientation (doesn’t respect lock)

screenOrientation: fullUser
Expected Result: User’s preferred orientation, or sensor (respects lock)
Result: Sensor that starts with User’s preferred orientation (doesn’t respect lock)

screenOrientation: nosensor
Expected Result: No Sensor
Result: Sensor that starts with Portrait (doesn’t respect lock)

With project.xml window orientation:

window: portrait
screenOrientation: sensorPortrait
Result: Portrait or Reverse Portrait (doesn’t respect lock)

window: landscape
screenOrientation: landscape
Result: Landscape or Reverse Landscape(doesn’t respect lock)

window: landscape
screenOrientation: portrait
Result: Landscape or Reverse Landscape (doesn’t respect lock)

The fix provided allowed for portrait/portrait reverse or landscape/landscape reverse, but it still doesn’t respect the user orientation and bypasses the screenOrientation in AndroidManifest.

So the original question still stands. Is there a way to do this?