Galaxy Tab 限量版中的相机图像捕捉意图无法返回
当我使用 Intent 打开相机时,我遇到了 Galaxy Tab 限量版 (Google I/O) 问题。
这是我的代码:
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mSavedFilePath))); startActivityForResult(imageCaptureIntent, REQUEST_IMAGE_CAPTURE);
在 Motorola Xoom 上,此代码运行良好。 但在 Galaxy Tab 10.1 上,我从未收到相机应用程序的响应。
我没有堆栈跟踪,因为我没有错误。
有人有什么想法吗?
I'm having problems with a Galaxy Tab Limited Edition ( Google I/O ) when I open the camera whit an Intent.
This is my code:
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mSavedFilePath))); startActivityForResult(imageCaptureIntent, REQUEST_IMAGE_CAPTURE);
On a Motorola Xoom this code is working fine.
But on Galaxy Tab 10.1, never I receive the response from the camera app.
I haven't a stack trace because i haven't an error.
Anyone have any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
启动相机应用程序的意图时,您不需要相机权限。
然而,这在android平台上是一个高度碎片化的过程。我对此有很多问题。基本上,如果您检查发送到相机应用程序的额外文件,您会注意到结果返回时他的大小为 0 字节。这个错误存在于很多 Android 设备中,您是修复大部分错误的解决方法,即当此错误失败时(这意味着没有返回可解析的额外输出,如果是,则不会创建额外文件或长度为 0那么你需要从意图中获取 Uri,例如:intent.getData(); 这将返回一个 uri 到文件,该文件的形成方式基本上与额外输出 Uri 相同,因此你可以使用相同的方法来获取图像 。
你会注意到 图像存储在 Media.Images 提供程序和相机目录中,并指向其中的 Intent.getData() Uri
希望这会有所帮助。
You don't need the camera permission when launching an intent to the camera app.
However this is a highly fragmented process on the android platform. i have had a lot of issues with it. basically if you check the extra file that you sent to the camera app you will notice that his size is 0 bytes when the result returns. this bug exists in a lot of android devices and thee is a workaround to fixing most of it and that is when this fails (this means there is no parceable extra output returned and if it is then the extra file is not created or with lenght 0 then you need to get the Uri from the intent like: intent.getData(); this will return an uri to the file which is basically formed the same way as the Extra Output Uri so you can afterwards use the same approach for obtaining the image.
You will notice the image is stored within the Media.Images provider and in the camera directory and ofc the intent.getData() Uri pointing in there.
Hope this helps. Don't forget to vote :D.
我也对此非常感到沮丧。然而,我确实找到了一个(相当可怜的)解决方法。
我应该说,我没有使用标准的 ACTION_IMAGE_CAPTURE Intent。因为我想在窗口中显示相机图像,所以我使用了自己的布局,并使用以下内容作为模板:
如何对 Google Android 相机进行编程以拍照
点击屏幕会调用 Camera.PictureCallback 函数 onPictureTaken(byte[] imageData, Camera c),这是我抓取包含图片的 byte[] 的地方。我有一个全局变量“byte[] MainApplication.snapshotBytes”,由该函数的 imageData 分配。
既然数据已全局保存,并且可供调用 Activity 使用,那么应如何终止当前 Activity 以便通知调用 Activity?嗯,方法有很多种,但我很早就意识到按后退按钮仍然会调用 OnActivityResult(...)。因此,我执行了以下操作:
调用 Activity 现在负责另外三件事。
1:它在启动相机 Activity 之前设置 MainApp.snapshotBytes = null。
2:当调用OnActivityResult(...)时,它首先检查*resultCode == RESULT_OK*,然后使用存储在全局MainApp.snapshotBytes中的图像数据。
3:最后再次设置MainApp.snapshotBytes = null,以便GC回收内存。
我将是第一个承认这是一个拼凑的人,但它可以工作并且与或不与 Camera-null-Intent 错误兼容。
我希望这有帮助!
I was very frustrated by this as well. However, I did find a (rather pitiful) workaround.
I should say, right off, that I was not using the standard ACTION_IMAGE_CAPTURE Intent. Because I wanted to have the camera image in a window, I used my own layout and I used the following as a template:
How to Program the Google Android Camera to Take Pictures
Tapping the screen calls the Camera.PictureCallback function onPictureTaken(byte[] imageData, Camera c), which is where I grab the byte[] containing the picture. I have a global variable "byte[] MainApplication.snapshotBytes" that is assigned by the imageData from this function.
Now that the data has been saved globally, and is available to the calling Activity, how should the current activity be terminated such that the calling activity is notified? Well, there are a number of ways, but I realized early on that pressing the back button still calls OnActivityResult(...). So, I did the following:
The calling Activity was now responsible for three more things.
1: It sets the MainApp.snapshotBytes = null before starting the camera Activity.
2: When the OnActivityResult(...) was called, it first checked the *resultCode == RESULT_OK*, and then made use of the image data that was stored in the global MainApp.snapshotBytes.
3: Finally, it set the MainApp.snapshotBytes = null again so that the memory could be reclaimed by GC.
I'll be the first one to admit that it's a kludge, but it works and is compatible with or without the Camera-null-Intent bug.
I hope this helps!
这听起来像是一个 Bug...
但以防万一,您是否在 AndroidManifest.xml 中包含以下内容???
您也可以尝试在没有额外内容的情况下使用 Intent。
生成的位图会更小,但至少您可以尝试看看它是否有效。
我希望它有帮助。
问候,
It sounds like a Bug...
But just in case, Have you included on your AndroidManifest.xml the following ???
Also you can try to use the Intent without extras.
The resulting bitmap will be smaller but at least you can try it to see if it works.
I hope it helps.
Regards,
听起来它可能与此相关 http://kevinpotgieter.wordpress.com/2011/03/30/null-intent-passed-back-on-samsung-galaxy-tab/
还有另一个 开放问题可能会给出 附加信息
Sounds like it could be related to this http://kevinpotgieter.wordpress.com/2011/03/30/null-intent-passed-back-on-samsung-galaxy-tab/
There is another open question which may give additional information