Eris 上的 EXTRA_OUTPUT 被忽略,导致 G1 上的数据返回 null

发布于 2024-10-04 11:55:28 字数 1117 浏览 0 评论 0原文

因此,我尝试使用以下代码启动相机活动:

//In public void captureImage()
...
Intent cameraIntent = new Intent(MediaStore.ACTION_CAPTURE_IMAGE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                      Uri.fromFile(new File("/sdcard/image.jpg")));
startActivityForResult(cameraIntent, REQUEST_CAMERA);

然后处理结果:

//In onActivityResult()
...
case REQUEST_CAMERA:
  Intent intent = new Intent (CurrentScreen.this, NextScreen.this);
  intent.putExtra(data);
  startActivity(intent);
  CurrentScreen.this.finish();
...

我使用 intent.putExtra(data) 将小位图附加到意图,并使用它作为下一个活动中的缩略图,完整大小的文件应该保存为 /sdcard/image.jpg

这是预期的行为(根据文档),缩略图有一个小位图,并保存一个大文件。然而,当在 G1 和 Eris 上进行测试时,我发现了一些奇怪的行为。

在 G1 上:

  • 虽然 resultCode 显示 RESULT_OK,但返回到结果处理程序的 Intent 数据为 null。
  • 另外 EXTRA_OUTPUT 似乎被完全忽略,我不知道它在哪里保存图像。

在 Eris 上:

  • 意图数据返回 OK
  • EXTRA_OUTPUT 也被忽略,但它将图像保存到 /sdcard/dcim/100media 的常规媒体存储

所以我的问题是:有什么办法使用标准相机活动获得我想要做的事情的一致行为?我可以编写一个自定义活动来尝试让它按照我想要的方式工作,但我宁愿避免这条路线。

So I'm trying to launch the Camera activity using the following code:

//In public void captureImage()
...
Intent cameraIntent = new Intent(MediaStore.ACTION_CAPTURE_IMAGE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                      Uri.fromFile(new File("/sdcard/image.jpg")));
startActivityForResult(cameraIntent, REQUEST_CAMERA);

And then to handle the result:

//In onActivityResult()
...
case REQUEST_CAMERA:
  Intent intent = new Intent (CurrentScreen.this, NextScreen.this);
  intent.putExtra(data);
  startActivity(intent);
  CurrentScreen.this.finish();
...

Where I use intent.putExtra(data) to attach the small bitmap to the intent, and use it as a thumbnail in the next activity, and the full sized file is supposedly saved as /sdcard/image.jpg.

This is the expected behavior (according to the documentation), to have a small bitmap for a thumbnail, and a large file saved. However when testing this on a G1 and an Eris, I have been seeing some strange behavior.

On the G1:

  • Although the resultCode shows RESULT_OK, the intent data that is returned to the result handler is null.
  • Also EXTRA_OUTPUT seems to be completely ignored, I have no idea where it is saving the image.

On the Eris:

  • The intent data comes back OK
  • EXTRA_OUTPUT is also ignored, but it is saving the images to the regular media store at /sdcard/dcim/100media

So my question is this: is there any way to get consistent behavior for what I am trying to do using the standard camera activity? I could write up a custom activity to try and get it to work the way I want, but I'd prefer to avoid that route.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2024-10-11 11:55:28

我没有你的问题的答案,因为我是 Java/Android 开发世界的新手。但我正在尝试类似于您正在做的事情,只是我想简单地拍摄照片然后将其附加到电子邮件中。

我实现了您的示例的一部分,并且能够验证相机是否创建了我指定的文件,并且如果我对下一张图片使用相同的文件名,它会覆盖前一个文件,这正是我所期望的。

但我真正想说的是,也许你必须测试“/sdcard/...”是否确实存在。您还可以通过将路径传递到下一个活动来简化流程。

祝你好运,

杰米·欧文

I do not have answers to your question as I am new to the Java/Android development world. But I am attempting something similar to what you are doing, except I want to simply take the picture then attach it to an Email message.

I implemented part of your example and was able to verify that the camera created the file I specified and that if I use the same file name for the next picture that it overwrites the previous file which is what I would expect.

But what I was really going to say is perhaps you will have to test if the pat "/sdcard/..." actually exists or not. Also you could possibly simplify your process by passing the path to the next activity.

Good Luck,

Jamie Irwin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文