Android : Prevent App for rotation landscape or portrait


If you want your app to have either of one fixed position: Landscape or Portrait, you can do it by setting the orientation in AndroidManifest.xml using android:screenOrientation attribute.

Example :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.code2care.tools.example"
   android:installLocation="auto"
   android:versionCode="1"
   android:versionName="1.0" >

<uses-sdk
   android:minSdkVersion="8"
   android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />

<application
   android:allowBackup="true"
   android:icon="@drawable/ic_launcher"
   android:installLocation="auto"
   android:label="@string/app_name"
   android:theme="@style/Theme.AppCompat.Light.NoActionBar" >

<activity
   android:screenOrientation="portrait"
   android:name=".MainActivity"
   android:label="@string/app_name" >

   <intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<activity
   android:name=".App"
   android:label="@string/app_name" >

</activity>
</application>

</manifest>

Note : If you have two or more activities then you need to set the orientation for each of them separately.

Example :