user3089184 user3089184 - 5 months ago 52
Android Question

PhoneGap/Android - Locking orientation to portrait

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

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

Comments