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?
How to prevent a Phonegap application to switch to landscape view
Asked Answered
im doing this in 2019 and <preference name="Orientation" value="landscape" /> works fine in debug build, "cordova run android" on an old Moto G4 phone plugged into usb –
Droughty
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.
Small piece of code and here you go. Try it.
<preference name="orientation" value="portrait" />
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
Thanks - I just put the
screen.lockOrientation
command in a platform ready callback. –
Grenadines 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. –
Happ
It wil be included in your project structure –
Highwrought
androidManifest.xml is in /platforms/android/ –
Latifundium
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? –
Happ
Then you might find this blog useful pervasivecode.blogspot.in/2011/11/… –
Highwrought
Phonegap 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 –
Highwrought
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 –
Highwrought
#7483100 here an another link you may or maynot find it usefull –
Highwrought
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. –
Happ © 2022 - 2024 — McMap. All rights reserved.