6

I am invoking a camera using an intent and clicking a picture. Presently I am on emulator and would like to force camera to click the pictures in portrait mode(need to capture a video of app working,so orientation change would look bad) but the camera screen appears landscape and all the further activities which I invoke in onActivityResult().

Camera Screen

After clicking the picture the Activity layout comes out in landscape mode like this: enter image description here

while all my previous activity have displayed correctly in portrait orientation. I tried adding

android:screenOrientation="portrait" 
android:configChanges="orientation|keyboardHidden"

to the activity shown above but to no avail.Though when i hit home and upon resume it displays correctly in portrait.

So how do I force portrait mode??

Sankalp
  • 1,128
  • 4
  • 14
  • 31

5 Answers5

2

None of the solutions work.There is nothing wrong with the layouts either.I got it to work by running on a higher version(API10 to API15). Weird!!

Sankalp
  • 1,128
  • 4
  • 14
  • 31
0

I think this is a known problem, see Camera|SetDisplayOrientation

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
0

You only need to set Id for each of your views. You don't need to force portrait mode in camera. Doing this, prevent the activity to recreate views and losing data

NBK.Nacer
  • 1
  • 2
-1

Write in your manifest.xml where you have defined your this activity.

<activity android:name="your_activity name" android:screenOrientation="portrait" />

This should work. I suggest you to check in real device.

use this code for your image capturing class where your preview is starting.

Dhruvisha
  • 2,538
  • 1
  • 21
  • 31
-2

This shoudl work:

 Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
 i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
 i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
 startActivityForResult(i, CAMERA_CODE); 
Manitoba
  • 8,522
  • 11
  • 60
  • 122