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:sc
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
<preference name="orientation" value="portrait" />
OR
<preference name="orientation" value="landscape" />
Please add android:screenOrientation="portrait"
in the androidManifest.xml
file as an attribute of activity tag for android.
<activity
android:name="com.example.demo_spinner.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
If you want to restrict to portrait mode only on all devices you should add this line to the config.xml in your projects root folder.
<preference name="orientation" value="portrait" />
After that, please rebuild the platform by typing below text in command line:
ionic build
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.
https://github.com/apache/cordova-plugin-screen-orientation
or try this code in xml config:-
<preference name="orientation" value="portrait" />
Inside your angular app.js
add the line screen.lockOrientation('portrait');
like shown bellow:
an
angular.module('app', ['ionic'])
.run(function($ionicPlatform) {
// LOCK ORIENTATION TO PORTRAIT.
screen.lockOrientation('portrait');
});
})
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 the cordova-plugin-device-orientation
First, you need to add the Cordova Screen Orientation Plugin using
cordova plugin add cordova-plugin-screen-orientation
and then add screen.lockOrientation('portrait');
to .run()
method
angular.module('myApp', [])
.run(function($ionicPlatform) {
screen.lockOrientation('portrait');
console.log('Orientation is ' + screen.orientation);
});
})