问题
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().

After clicking the picture the Activity layout comes out in landscape mode like this:

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??
回答1:
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!!
回答2:
I think this is a known problem, see Camera|SetDisplayOrientation
回答3:
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
回答4:
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.
回答5:
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);
来源:https://stackoverflow.com/questions/9908387/force-portrait-mode-in-camera