I'm working on Ionic/Cordova, I added this to androidManifest.xml
but this didn't work for me and app is still showing in both ways
android:screenOrientation="portrait"
How can I restrict my app to portrait mode only? I have checked on android and it doesn't work
According to https://cordova.apache.org/docs/en/4.0.0/config_ref/#global-preferences,
<preference name="Orientation" value="landscape" />
Be aware that these values are case sensitive, it is "Orientation", not "orientation".
If you want to do something on your orientation means you want to perform any action when change your app orientation then you have to use ionic framework plugin... https://ionicframework.com/docs/native/screen-orientation/
If you just want to restrict your app on portrait or landscape mode then you have to just add these following line in your config.xml
Inside your angular
app.js
add the linescreen.lockOrientation('portrait');
like shown bellow:an
You will also have other code in the
.run
function, but the one you are interested in is the line I wrote. I haven't added the line<preference name="orientation" value="portrait" />
in my code, but you may need to add thecordova-plugin-device-orientation
In config.xml add the following line
You can try this:-
Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on an early version of Screen Orientation API so the api does not currently match the current spec.
or try this code in xml config:-
First, you need to add the Cordova Screen Orientation Plugin using
and then add
screen.lockOrientation('portrait');
to.run()
method