Qt android screen orientation
Unsolved
Mobile and Embedded
-
Hi,
Is there a way to set the screen orientation in Qt 5.12.3 programmatically, and without changing the AndroidManifest.xml file ?
@zine Hi, it is simple to change screen orientation from Qt:
enum Orientation { Unlocked = 4, // SCREEN_ORIENTATION_SENSOR (Android) LandscapeLocked = 0, // SCREEN_ORIENTATION_LANDSCAPE (Android) PortraitLocked = 1, // SCREEN_ORIENTATION_PORTRAIT (Android) }; void setOrientation(Orientation orientation) { const QAndroidJniObject Activity = QtAndroid::androidActivity(); QAndroidJniEnvironment JniEnv; Activity.callMethod<void>("setRequestedOrientation", "(I)V", orientation); if(JniEnv->ExceptionCheck()) { qDebug() << "setOrientation:: failed to set orientation!!!"; JniEnv->ExceptionDescribe(); JniEnv->ExceptionClear(); } }