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?
Asked
Active
Viewed 1.4k times
23

DMEM
- 1,573
- 8
- 25
- 43
-
im doing this in 2019 and
works fine in debug build, "cordova run android" on an old Moto G4 phone plugged into usb – don bright Jun 24 '19 at 00:07
4 Answers
36
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.

DMEM
- 1,573
- 8
- 25
- 43
9
Small piece of code and here you go. Try it.
<preference name="orientation" value="portrait" />

Ashish
- 1,978
- 1
- 15
- 7
8
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

hotzst
- 7,238
- 9
- 41
- 64

Yacine Tachoua
- 81
- 1
- 1
-
Thanks - I just put the `screen.lockOrientation` command in a [platform ready](http://ionicframework.com/docs/api/utility/ionic.Platform/#ready) callback. – Dunc Apr 14 '16 at 11:32
-3
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
-
How do I get to the androidManifest.xml file? I've seen this answer before but I couldn't find how to add or edit this file. – DMEM May 15 '14 at 14:14
-
-
-
I don't have this path. I'm building my project at build.phonegap.com with my github repository, is that why I don't have this folder? – DMEM May 15 '14 at 18:14
-
Then you might find this blog useful http://pervasivecode.blogspot.in/2011/11/phonegap-build-editing.html?m=1 – ShinyJos May 15 '14 at 20:46
-
1Phonegap usually autogenerates androidmanifest based on your config file..it resides under your res or android folder depending on version you use..but if you are using phonegap site to generate apk you might nt have access to it. The above link will be usefull – ShinyJos May 15 '14 at 20:50
-
When you buid project via cli..if will fall in your project structure and you can edit it.. but in phonegap build it falls inside your apk – ShinyJos May 15 '14 at 20:59
-
http://stackoverflow.com/questions/7482600/how-to-fix-screen-orientation-to-potrait-for-my-whole-phonegap-app here an another link you may or maynot find it usefull – ShinyJos May 15 '14 at 21:10
-
Ok, so I decompiled my apk and I've opened the `androidManifest.xml`, however, the line : `android:screenOrientation="portrait"` was already there. I tried to add it anyway in a new activity but unfortunately, the recompiled apk cannot be installed on my phone (regardless to the manifest edit, it's something to do with the decompile and recompile process). Anyway, since the orientation definition was already there, I think my problem lies somewhere else. – DMEM May 15 '14 at 21:58