How to fix screen orientation to portrait for my whole PhoneGap app

17,183

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" > 
Share:
17,183
Vinayak Bevinakatti
Author by

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, 2022

Comments

  • Vinayak Bevinakatti
    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
    Vinayak Bevinakatti over 12 years
    I dont want to do it for only Android, is there any platform independent approach
  • Maulik J
    Maulik J over 12 years
    then u must set the orientation logically in your class file.
  • Vinayak Bevinakatti
    Vinayak Bevinakatti over 12 years
    Could you please elaborate more about how to do it, Please modify your answer accordingly, Thanks for the response.
  • Hola Soy Edu Feliz Navidad
    Hola Soy Edu Feliz Navidad about 11 years
    It's true, the documentation says that, but it never worked form me with Android, only the Android manifest configuration.
  • hallodom
    hallodom about 11 years
    I think that's if you're using Phonegap build only which is a separate too?
  • hallodom
    hallodom about 11 years
    Thanks 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
    pjnovas over 10 years
    doesn'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
    avolquez about 10 years
    @Maulik J Thank you, it was helpful for me!
  • gnganapath
    gnganapath over 9 years
    Used 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