Usman Khan
Usman Khan

Reputation: 3953

How to set the camera orientation in Android?

I am working on Android application in which I am taking picture from camera. I just want to set my camera orientation to be portrait. My code is given below from where I am sending request to OnActivityResult:

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
            ContentValues values = new ContentValues(3);  
            values.put(MediaStore.Images.Media.DISPLAY_NAME, "testing");  
            values.put(MediaStore.Images.Media.DESCRIPTION, "this is description");  
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");  
            imageFilePath = UserInfoActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
 startActivityForResult(intent, 0); 

Upvotes: 0

Views: 2608

Answers (1)

Hemz
Hemz

Reputation: 223

Add these lines in your code

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);   
    startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 

Add these lines in your Manifest.XML

<activity
     android:name="ActivityName"
     android:screenOrientation="portrait"
     android:configChanges="orientation" >
     </activity>

Upvotes: 3

Related Questions