21

I have tried every method to lock the screen to portrait orientation but they simply do not work after testing the app via Adobe PhoneGap Build.

Firstly, I have modified the MainActivity.java file to include at onCreate

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Secondly, I have modified the config.xml file to include

<preference name="orientation" value="portrait" />

Thirdly, I have modified the Manifest file to include

android:screenOrientation="portrait"

None of the above are working.

user3089184
  • 241
  • 1
  • 3
  • 7
  • I have just tested this through the Eclipse AVD and the screen orientation locks as intended. Any idea why this is not the case when running the app via PhoneGap Build? – user3089184 May 28 '14 at 11:04

3 Answers3

26

Update the config.xml File which is in your project folder, above www.

Add the line:-

<preference name="orientation" value="portrait" />

Then build you project & there will be no Orientation Change.

In place of "portrait" you can use "landscape".

1615903
  • 32,635
  • 12
  • 70
  • 99
user3094755
  • 1,561
  • 16
  • 20
  • Hi, doing this will lock the app in portrait, however, it seems the camera is not respecting that, the camera rotates to orientation of the device. – olanchuy Sep 21 '16 at 02:51
  • @olanchuy - Of course; the camera is a separate app. – klidifia Mar 16 '17 at 00:53
22

If you're using Cordova 3.4.1 <preference name="orientation" value="portrait" /> should work.

Also, don't forget to add: android:configChanges="orientation" in the activity tag.

Else, you can try using this plugin: https://github.com/cogitor/PhoneGap-OrientationLock

magicode118
  • 1,444
  • 2
  • 17
  • 26
  • 10
    Hey @zalow517, what is the "activity tag" you were refering to? (to add `android:configChanges="orientation"`) – Debnath Sinha Jan 31 '15 at 21:19
  • Mentioned plugin is deprecated, use this one: http://stackoverflow.com/a/32405384/1848600 , for Cordova 4.0 + – Gajotres Sep 04 '15 at 20:23
  • The Cordova docs show "Orientation" with a capital "O". Does that matter? –  Mar 15 '17 at 06:56
  • Be aware that these values are case sensitive, it is "Orientation", not "orientation". – LeRoy Oct 28 '21 at 05:22
2

just put below in activity tag below application tag in android manifest.xml file

android:screenOrientation="portrait"

Thanks

Adarsh Nahar
  • 319
  • 3
  • 10