2

I created a Qt/QML application and ported the application to Android. Now I'm able to run the application on the Android device. I want to fix the orientation mode to Landscape.

I manually edited the AndroidManifest.xml and set the android:screenOrientation="unspecified" to android:screenOrientation="sensorLandscape"

<activity
  android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
  android:name="org.qtproject.qt5.android.bindings.QtActivity"
  android:label="Engage"
  android:screenOrientation="sensorLandscape"
  android:launchMode="singleTop">

Each time when I deploy the project, the manifest is overwritten and reset to android:screenOrientation="unspecified"

pasbi
  • 1,957
  • 1
  • 17
  • 27
Vineesh TP
  • 7,389
  • 10
  • 58
  • 118
  • Did you clear before building? `android:screenOrientation="landscape"`as always worked for me and also `sensorLandscape` worked nice in a quick check. – BaCaRoZzo Jan 09 '17 at 13:32
  • Yes I cleared the build. Also when deploy the application it reset to 'unspecified' – Vineesh TP Jan 10 '17 at 03:33
  • possibly related: [Temporarily, programmatically disable screen rotation in Qt](https://stackoverflow.com/q/34310349/4248972) – pasbi Mar 13 '19 at 14:20

2 Answers2

3

I got a solution for this.

Add a folder in your project folder. I have named 'android-sources'. Copy your AndroidManifest.xml from android-build and paste to 'android-sources' folder. Open .pro file and add the following

OTHER_FILES += \
    android-sources/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources

Then open the AndroidManifest.xml

change the orientation

android:screenOrientation="sensorLandscape"
Vineesh TP
  • 7,389
  • 10
  • 58
  • 118
  • 1
    What the other answser says was exactly this, expected that you don't have to manually edit the pro.... – BaCaRoZzo Jan 10 '17 at 08:28
2

On Qt Forum the following solution is suggested:

Just go to the projects, running, click on details and create androidmanifest.xml, choose a directory. After that add it to your project if it didnt happen automatically and edit it. 4th line should look like this:

@<activity android:screenOrientation="unspecified" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="@string/app_name">@ 

just change "unspecified" to "sensorLandscape" and save it.

It won't be overwritten every time you deploy.

demonplus
  • 5,320
  • 11
  • 48
  • 64