简体   繁体   English

通过Intent使用手机摄像头 - 活动永远不会返回?

[英]Using phone camera via Intent - activity never returns?

I'm using the phone's camera in an Android app to take a photo. 我在Android应用中使用手机的相机来拍照。 I'm using Intents to use the built-in camera application and I'm using the following code: 我正在使用Intents来使用内置的相机应用程序,我使用以下代码:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(FILEPATH)));
startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE);

It works fine and the camera is brought up. 它工作正常,相机也可以显示出来。 I can take a photo and the phone presents me with three options: Cancel, Retake, OK. 我可以拍照,手机给我提供了三个选项:取消,重拍,确定。 The first two work, pressing cancel returns the user to the app, but pressing OK and nothing happens. 前两个工作,按取消将用户返回到应用程序,但按下确定没有任何反应 Apparently onActivityResult isn't being called, and the camera just stays on the screen. 显然onActivityResult没有被调用,相机只是停留在屏幕上。 Nothing in the debugger either. 调试器中也没有。

Running the app on a Nexus One with Android 2.2.1. 使用Android 2.2.1在Nexus One上运行应用程序。 Same problem on the emulator running Android 2.0. 运行Android 2.0的模拟器上的问题相同。

Edit : Tested on a HTC Desire running Android 2.2 with HTC's Sense UI: works perfectly. 编辑 :使用HTC的Sense UI在运行Android 2.2的HTC Desire上进行测试:效果很好。 Nothing on the emalator nor Google N1. 电子邮件中没有任何内容,也没有Google N1。

Edit2 : It seems that the HTC Desire image aquiring activity works better in the sense that it does return, but it disregards the EXTRA_OUTPUT -setting and returns only a small image in the onActivityResult -call. 编辑2 :似乎HTC Desire图像获取活动在它确实返回的意义上更好地工作,但是它忽略了EXTRA_OUTPUT设置并且仅在onActivityResult -call中返回一个小图像。 Checking on the ddms console while the phone is hooked to the computer I see that the phone is storing the image on the SD card, but the path is not passed back to my application. 在手机连接到计算机时检查ddms控制台我看到手机正在将图像存储在SD卡上,但路径不会传回我的应用程序。 It is starting to look like there is no reliable way to use the camera intent, and get back a reasonably-sized image. 它开始看起来没有可靠的方式来使用相机意图,并获得一个合理大小的图像。 Bad, bad, bad. 坏,坏,坏。

After a bit of research, testing and sheer luck I managed to solve this issue. 经过一番研究,测试和纯粹的运气,我设法解决了这个问题。

If the EXTRA_OUTPUT -option for the Intent contains a file URI that points to the internal memory of the device, the call will fail. 如果Intent的EXTRA_OUTPUT -option包含指向设备内部存储器的文件URI,则调用将失败。 How it fails, depends on the device. 它如何失败取决于设备。 The HTC Desire works ok on the surface, but fails to return the full-sized image. HTC Desire在表面上工作正常,但无法返回全尺寸图像。 Google N1 on the other hand refuses to leave from the camera activity. 另一方面,谷歌N1拒绝离开相机活动。

When I changed the file URI to point to the memory card, it worked perfectly for both the Desire and Google N1. 当我将文件URI更改为指向存储卡时,它对Desire和Google N1都有效。

So summing it up: the path to store the full sized image MUST point to the SD card. 总而言之:存储全尺寸图像的路径必须指向SD卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM