使用意图在人像模式下打开相机 [英] Opening Camera in Portrait mode using Intent

查看:87
本文介绍了使用意图在人像模式下打开相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Intent从我的Activity打开设备的相机,如下所示:

I am able to open the device's Camera from my Activity using an Intent as follows:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = getOutputMediaFileUri();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(cameraIntent, CAMERA_REQUEST);

我的问题是我的Activity设置为风景模式,因此当打开相机时,它也以风景模式打开-但我需要打开只能在 Portrait 模式下使用相机.

My problem is my Activity is set to Landscape mode, so when the camera is opened, it is also opened in Landscape mode - but I need to open the Camera in Portrait mode only.

因此,请让我知道使用Intent启动设备的相机时该怎么做.

So please let me know how can I do this when using an Intent to launch the device's camera.

谢谢...

推荐答案

这是使用外部应用程序为您处理功能的问题.从理论上讲,接受Intent动作的应用应正确处理Intent并返回您要的数据,但实际上您几乎无法采取措施来强制执行此行为...例如,任何应用都可以说它可以处理图像捕获",但是如果您将Intent传递给编程不良或恶意的应用程序,则没有什么可以阻止该应用程序执行与您的意图完全不同的事情,或者什么也不做.如果您选择让您的应用程序放弃对另一个应用程序的控制以实现某些功能,则冒着选择任何应用程序都无法实现该功能的风险.

This is an issue with using external apps to handle functionality for you. In theory, apps that accept Intent actions should properly handle the Intent and return the data you are asking for, but in practice there is very little you can do to enforce this behavior...For example, any app can say it handles "image capture," but if you were to pass your Intent to a poorly programmed or malicious app, there is nothing preventing that app from doing something completely different than what you intended, or nothing at all. If you choose to let your app give up control to another app to fulfill certain functionality, you take the risk that whatever app is chosen cannot fulfill that functionality.

在您要添加Intent附加功能的特殊情况下,任何人都无法回答这个问题,该问题将适用于所有相机应用程序.您将需要找到一个支持您想要的内容的应用程序,弄清楚如何将其强制设置为纵向模式,然后祈祷所有用户都安装了该特定应用程序.几乎没有什么选择可以始终确保您的应用以您想要的方式拍照:

In your particular case where you are looking for the ability to add Intent extras, there is no way anyone can answer this question that would apply to all camera apps out there. You would need to find one that supports what you want, figure out how to force it into portrait mode, and then pray that all your users have that particular app installed. The are really very few options to always ensure that your app will take a picture the way you want it to:

  • 为相机Intent创建一个选择器,并将结果限制为仅已测试并且知道可以正常工作的应用程序.如果未安装特定的应用程序,请禁用拍照功能.
  • 实施图像捕获自己.

这篇关于使用意图在人像模式下打开相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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