Force portrait mode in camera

十年热恋 提交于 2019-11-29 10:43:46

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!!

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

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

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.

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); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!