How to lock the camera app orientation called through intent in android?

浪子不回头ぞ 提交于 2019-12-12 09:03:32

问题


I want to open the native camera app through intent in my application. I have used the following lines of code.

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(takePictureIntent, actionCode);

Now, I want to lock the orientation of camera in portrait when it is opened. I just added the below line to the above piece of code.

takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
                    ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

But, it is not working. The Camera opened is not locked to portrait. It is moving in all the orientation. Please help me to solve this issue.

Thanks in Advance !!!


回答1:


To force portrait orientation:

place android:screenOrientation="portrait" in your AndroidManifest.xml



来源:https://stackoverflow.com/questions/20651019/how-to-lock-the-camera-app-orientation-called-through-intent-in-android

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