PhoneGap/Android - Locking orientation to portrait

user3089184 picture user3089184 · May 28, 2014 · Viewed 31.9k times · Source

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.

Answer

user3094755 picture user3094755 · May 27, 2015

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".