How to prevent a Phonegap application to switch to

2019-03-24 06:13发布

This one should be very simple, however it's not. I'm trying to prevent my application from going into landscape view so I've changed the config.xml file like this: <preference name="orientation" value="portrait" />. Unfortunately, it's not working. Any ideas?

4条回答
冷血范
2楼-- · 2019-03-24 06:49

For platform android just set prefered orientation in androidManifest.xml like this

 <activity
        android:name="com.payoda.Insurance.SplashScreenActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
    >
    </activity>

For IOS the following link may help you

Force portrait orientation on iPhone with phonegap

查看更多
别忘想泡老子
3楼-- · 2019-03-24 07:01

Small piece of code and here you go. Try it.

<preference name="orientation" value="portrait" />
查看更多
祖国的老花朵
4楼-- · 2019-03-24 07:03

Ok, so I got it: The reason Phonegap ignored the <preference name="orientation" value="portrait" /> in the config.xml file is because my app was in debug mode. once I created a release version it stopped from going to landscape.

查看更多
我只想做你的唯一
5楼-- · 2019-03-24 07:15

hello you can install this plugin https://github.com/gbenvenuti/cordova-plugin-screen-orientation

and add this function on you index.js or one of your first executed js document

window.addEventListener("orientationchange", function(){
    screen.lockOrientation('portrait');
});

thank u

查看更多
登录 后发表回答