Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap/Android - Locking orientation to portrait

Tags:

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.

like image 544
user3089184 Avatar asked May 28 '14 10:05

user3089184


People also ask

How do I lock portrait orientation on Android?

Open Quick settings again. Whether you are holding your device upwards or sideways, swipe down from the top of the screen. Tap the Auto rotate icon to lock your device in your desired position. Remember, Portrait is when the device is upwards, and Landscape is when the device is sideways.

How do I lock screen in vertical position?

If you don't want the screen to switch between portrait and landscape when you move the device, you can lock the screen orientation. To do this, swipe down from the right side of the top panel. Hold the device in the orientation in which you want it locked. On the drop-down menu, touch the “Auto Rotate” button.

Where is portrait orientation on Android?

Swipe down again from the Quick Settings menu. 3. Tap the Auto Rotate/Portrait/Landscape icon.


2 Answers

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

like image 130
user3094755 Avatar answered Oct 14 '22 01:10

user3094755


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

like image 22
magicode118 Avatar answered Oct 14 '22 00:10

magicode118