How to fix screen orientation to portrait for my whole PhoneGap app
Solution 1
To fix your orientation in portrait mode just add the below line in your activity tag in AndroidManifest.xml file:
android:screenOrientation="portrait"
or this in the activity class:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Solution 2
Actually you can use config.xml to set it to all devices if you're using PhoneGap Build...
Set the propertie: orientation with possible values default, landscape, or portrait
example:
< preference name="orientation" value="landscape" />
*please note that default means both landscape and portrait are enabled.
Source:
https://build.phonegap.com/docs/config-xml
Solution 3
use this code in your manifest
<activity android:name=".DroidGap"
android:label="@string/app_name"
android:screenOrientation="landscape" >
Vinayak Bevinakatti
Hi! I am an experienced mobile app enthusiast. I enjoy creating apps for Android and iOS. I've worked on Android, iOS, BlackBerry platforms for developing both native and hybrid apps. "Be Proactive, Not Reactive"
Updated on June 03, 2022Comments
-
Vinayak Bevinakatti almost 2 years
How to configure the Phonegap app to be fixed to only portrait mode, I there any possibility to do it with CSS or JavaScript so that I should be able to get the consistent behaviour across the platforms
I found this useful post detecting-displays-orientation-change-on-mobile-devices-with-accelerometer-a-platform-indipendent-approach
Here it is explained how to detect the orientation, but I need to configure it
Is it possible through CSS3 Media queries?
-
Vinayak Bevinakatti over 12 yearsI dont want to do it for only Android, is there any platform independent approach
-
Maulik J over 12 yearsthen u must set the orientation logically in your class file.
-
Vinayak Bevinakatti over 12 yearsCould you please elaborate more about how to do it, Please modify your answer accordingly, Thanks for the response.
-
Hola Soy Edu Feliz Navidad about 11 yearsIt's true, the documentation says that, but it never worked form me with Android, only the Android manifest configuration.
-
hallodom about 11 yearsI think that's if you're using Phonegap build only which is a separate too?
-
hallodom about 11 yearsThanks for the response. I had the same issue and couldn't find it in phonegap docs. Can you point to any docs around this?
-
pjnovas over 10 yearsdoesn't work for me either ... that is the best solution, cause if I change the manifest I'll lose it after build the phonegap app again.
-
avolquez about 10 years@Maulik J Thank you, it was helpful for me!
-
gnganapath over 9 yearsUsed Version Cordova 4.0.0.., I fixed/ placed this line in my cofig.XML file. It's working for Android. App run value = "portrait" or "landscape" Mode Alone. Command Line Method it's working