N
N
Nikita Derbenev2020-07-26 21:52:25
Android
Nikita Derbenev, 2020-07-26 21:52:25

How to change android screen orientation using only native code?

I need to switch to landscape mode for my game. I only use native c++ code without java.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.habebu.podval"
    android:versionCode="1"
    android:versionName="1.0"
    android:installLocation="auto"
    android:screenOrientation="landscape"> <!-- НЕ РАБОТАЕТ -->
    <uses-feature android:glEsVersion="0x00020000" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.usb.host"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.type.pc"
        android:required="false" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:allowBackup="true"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:hardwareAccelerated="true" >
     <activity
     android:name="LaunchActivity"      
     android:screenOrientation="landscape"></activity>
        <activity android:name="showimageActivity"
            android:label="@string/app_name"
            android:alwaysRetainTaskState="true"
            android:launchMode="singleInstance"
            android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


How to correctly change the orientation of the application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-07-26
@Nikita_yfh

android:screenOrientation="landscape"> <!-- НЕ РАБОТАЕТ -->

Because the manifest does not have such an attribute. Set it to active.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question