How to lock the orientation to Portrait when using intent ACTION_IMAGE_CAPTURE?

断了今生、忘了曾经 提交于 2019-11-28 08:50:44

问题


I know I can set the orientation of the activity in the manifest, but when this activity is calling the MediaStore.ACTION_IMAGE_CAPTURE to open the camera and take a photo, the user can still take photos in landscape mode. Can I lock the orientation of the camera app itself to portrait?

Here is a sample code:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
startActivityForResult(intent, TAKE_PICTURE);

I would like to prevent the user from taking any landscape photos.

Any help would be greatly appreciated.

EDIT: Found another question on the topic that hasn't been answered: How to lock the camera app orientation called through intent in android?


回答1:


After spending some time with it, it seems like it's not possible to lock the orientation to Portrait, when using the Intent MediaStore.ACTION_IMAGE_CAPTURE.

So I decided to implement a custom camera and set the orientation in the code, via the setDisplayOrientation method, as suggested in the comments.

Basically, that's not a solution to the problem, but just another way to "tackle" it, however it suits my case because I was also able to handle the user interface and make some changes in regards to the default interface.



来源:https://stackoverflow.com/questions/32427596/how-to-lock-the-orientation-to-portrait-when-using-intent-action-image-capture

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