使用意图ACTION_IMAGE_CAPTURE时如何将方向锁定为纵向? [英] How to lock the orientation to Portrait when using intent ACTION_IMAGE_CAPTURE?

查看:242
本文介绍了使用意图ACTION_IMAGE_CAPTURE时如何将方向锁定为纵向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在清单中设置活动的方向,但是当此活动调用MediaStore.ACTION_IMAGE_CAPTURE打开相机并拍照时,用户仍可以在横向模式下拍照.我可以将相机应用本身的方向锁定为纵向吗?

这是示例代码:

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

我想防止用户拍摄任何风景照.

任何帮助将不胜感激.

编辑:找到了另一个尚未回答的问题: 如何锁定称为是通过android中的意图实现的?

解决方案

花了一些时间后,使用Intent MediaStore.ACTION_IMAGE_CAPTURE时似乎无法将方向锁定为纵向".

因此,我决定实现自定义摄像头,并按照注释中的建议通过setDisplayOrientation方法在代码中设置方向.

基本上,这不是解决问题的方法,而只是解决"问题的另一种方法,但是它适合我的情况,因为我也能够处理用户界面并对默认界面进行一些更改./p>

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?

解决方案

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.

这篇关于使用意图ACTION_IMAGE_CAPTURE时如何将方向锁定为纵向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆