0

I just had a basic question regarding the orientation. Currently my app just supports phones in portrait mode only. I just altered it to support tablets, but I am wondering how I can make it work for both orientations for tablet, keeping the phone orientation to portrait. Here is part of the code in my manifest for setting it to portrait:

<activity
            android:name=".activities.SplashActivity"
            android:clearTaskOnLaunch="true"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:theme="@style/AppBaseTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="https" android:path="/msf1.0/public/mobilebootstrapper.aspx"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateUnchanged|adjustResize" >
        </activity>
krsteeve
  • 1,794
  • 4
  • 19
  • 29

1 Answers1

3

You can call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ine the onCreate method of your Activity if the device is a phone. To determine if the device is a phone or a tablet, you can have a look at this question.

Community
  • 1
  • 1
2Dee
  • 8,609
  • 7
  • 42
  • 53
  • so I basically set setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); for tablet? –  Oct 17 '13 at 17:20
  • 1
    If you want the device to recognize orientation based on the orientation sensor, you need to set it to ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR. All constants are explained here : http://developer.android.com/reference/android/R.attr.html#screenOrientation – 2Dee Oct 17 '13 at 17:24
  • what do i do with the screenorientation defined in manifest as portrait? –  Oct 17 '13 at 17:26
  • You could remove it for that activity node. – 2Dee Oct 18 '13 at 07:43
  • If you open your application in Landscape in Phone, then the app opens in landscape mode and then shifts to Portrait Mode. This does not solve the issue completely – abhishek maharajpet Sep 05 '19 at 08:34