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
  • 2,037
  • 1
  • 20
  • 32
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
  • 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

3 Answers3

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,755
  • 12
  • 66
  • 130
  • 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
1

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,613
  • 12
  • 49
  • 68
0

I got the same problem as you, finally I found the solution for this question. Follow these steps:

  1. Select Projects > Build > Build Android APK > Create Templates.

  2. Check the path in Android package source directory.

  3. Select Copy the Gradle files to Android directory if you plan to extend the Java part of your Qt application

  4. Select Finish to copy the template files to the android directory and to open the manifest file for editing.

  5. In screen orientation field select "SensorLandscape". enter image description here

Zappy.Mans
  • 551
  • 1
  • 7
  • 19