PhoneGap - Forcing Landscape orientation

橙三吉。 提交于 2019-11-26 16:37:21
mayur rahatekar

Have you tried this?

android:screenOrientation="portrait"

Inside the AndroidManifest.xml file, where you have declared your activity, just add the above line.

For example:

<activity
            android:name=".Activity.SplashScreenActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action
                    android:name="android.intent.action.MAIN" />
                <category
                    android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

The correct way to do this for all devices is to configure config.xml

<preference name="orientation" value="portrait" />

<preference name="orientation" value="landscape" />

https://build.phonegap.com/docs/config-xml

It is very simple, you need to add android:screenOrientation="landscape" in your AndroidManifest.xml file.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".LogUploaderActivity" android:label="Log Uploader" android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
jyotiprakash

Please try this in your activity. Inside onCreate() and before setContentView.

// keeps the screen orientation in Landscape mode
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Maybe important to mention because i did not know it:

If you use the online phonegap apk converter with hydration enabled to your application, u'll have to rebuild your app completly instead of just update it. This will help you also with preferences like "orientation" or "fullscreen" !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!