lock your camera view to landscape mode in android

Kush Patel picture Kush Patel · Oct 1, 2012 · Viewed 7.7k times · Source

I want to lock my camera view to "Landscape" mode.When I click on the simple button in my app, that time device's camera will open and and that camera should be locked to "Landscape mode". Can anyone know the solution of this problem?

I am using this code inside "CaptureImageActivity.java" activity. So after execution of this activity my system's camera will open.

btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent i=new Intent(android.provider.MediaStore. ACTION_IMAGE_CAPTURE);
            i.putExtra(android.provider.MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


            startActivityForResult(i,1000);

        }
    });

And I want to lock that camera view to "LandScape Mode". And as per solution

<activity android:name=".CaptureImageActivity"
    android:screenOrientation="landscape"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Only "CaptureImageActivity" activity is locked to "LandScape Mode".

Answer

Shruti picture Shruti · Oct 1, 2012

see this link to lock your camera orientation,use setDisplayOrientation (int degrees)

documentation can be found on following link : http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29

for more details see this answer :

How to set Android camera orientation properly?