Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova/Ionic - Set Portrait Only Mode for Mobiles and allow Orientation in Tablets

How do we set Mobile phones to Portrait only and allow tablets to switch between portrait and landscape?

I am using Ionic/Cordova.

Currently I have configured to set the app to be in portrait mode in config.xml using the following property

 <preference name="orientation" value="portrait" />
like image 534
nijin Avatar asked Jan 14 '16 07:01

nijin


People also ask

How to unlock screen orientation in ionic with Cordova?

Using the ionic native and Cordova plugin, we can access the PORTRAIT and LANDSCAPE methods to lock the screen. Similarly, we can access the unlock method to unlock the screen orientation in Ionic. Let us combine all the methods and functions to give you the final code of this tutorial. Open home.page.ts file, and update with the given below code:

Which orientation is in the secondary portrait mode?

The orientation is in the secondary portrait mode. The orientation is in the primary landscape mode. The orientation is in the secondary landscape mode. The orientation is either portrait-primary or portrait-secondary (sensor). The orientation is either landscape-primary or landscape-secondary (sensor).

How to set the orientation of screen in Android programmatically?

1. Add android:screenOrientation="portrait" to the activity in the AndroidManifest.xml. 2. Setting programmatically in Java Note : In Activity you should call this before setContentView in onCreate () method.

How to achieve activity level orientation control in Android?

There are 2 ways to achieve Activity level Orientation control. 1. Add android:screenOrientation="portrait" to the activity in the AndroidManifest.xml. 2. Setting programmatically in Java


1 Answers

You could use isTablet plugin in conjunction with screen orientation plugin, something like:

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.isTablet){
        screen.unlockOrientation();
    }else{
        screen.lockOrientation('portrait');
    } 
  });
})
like image 113
DaveAlden Avatar answered Oct 20 '22 10:10

DaveAlden