打开自定义相机,拍照,保存图片,发送图片

发布于 2024-11-15 06:01:11 字数 1305 浏览 2 评论 0原文

这次我有一个关于 Android 自定义相机的问题,而不是可通过 Camera_intent 访问的内置相机。我不被允许使用那个。我试图做的是允许用户将相机瞄准某物并在 onOptionsItemMenu 上选择“发送”。

我在单独实施这个方面没有任何问题。如果我要求它通过单击按钮发送某些内容,它就会发送。如果我告诉相机保存照片而不发送它,它就会保存。

当我尝试同时做这两件事时,我遇到了问题。就目前情况而言,使用以下代码:

 public boolean onOptionsItemSelected(MenuItem item) {
        Intent i;
        File file2;
        camera.takePicture(null, mPictureCallback, mPictureCallback);
        switch (item.getItemId()) {

        case R.id.save:
            return super.onOptionsItemSelected(item);

        case R.id.send:

            file2 = new File(filename);
            i = new Intent(Intent.ACTION_SEND);
            i.putExtra(Intent.EXTRA_SUBJECT, "Sample Picture");
            System.out.println("file//" + file2);
            i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file//" + file2));
            i.setType("image/png");
            startActivity(Intent.createChooser(i, "Email file"));
            finish();
            return super.onOptionsItemSelected(item);

相机“点击”或“闪烁”,就像正在拍照一样,然后立即打开邮件客户端选择。当我选择要使用 Gmail 的位置时,提示该位置为空。但是,如果我删除启动电子邮件选择器的部分,图像将正确保存并存在。

几乎就好像它跳过了那个相机采取的步骤。

我确信解决这个问题的方法很简单,我现在只是脑子不够用,可能因为树木而看不到森林。 (如果这个类比就是这么说的话)。

我是否在另一个线程上运行相机部分?

我的一个想法是使用布尔值来检查文件的存在和大小,但我不确定如何让程序一遍又一遍地检查直到它返回 true。

I have a question this time around regarding the Android custom camera, NOT the built in camera that is accessible through Camera_intent. I am not permitted to use that one. What I am attempting to do is allow a user to aim the camera at something and choose "Send" on the onOptionsItemMenu.

I am not having any issues getting this implemented...separately. If I ask it to send something with the click of a button, it sends. If I tell the camera to save the picture without sending it, it does.

I run into a problem when I try to do both. As it stands, using this code:

 public boolean onOptionsItemSelected(MenuItem item) {
        Intent i;
        File file2;
        camera.takePicture(null, mPictureCallback, mPictureCallback);
        switch (item.getItemId()) {

        case R.id.save:
            return super.onOptionsItemSelected(item);

        case R.id.send:

            file2 = new File(filename);
            i = new Intent(Intent.ACTION_SEND);
            i.putExtra(Intent.EXTRA_SUBJECT, "Sample Picture");
            System.out.println("file//" + file2);
            i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file//" + file2));
            i.setType("image/png");
            startActivity(Intent.createChooser(i, "Email file"));
            finish();
            return super.onOptionsItemSelected(item);

The camera "clicks" or "flickers" as if it is taking the picture and then it immediately opens the mail client choose. When I select which I want to take Gmail is saying that the location is null. However if I remove the part that starts the email chooser, the image saves properly and is there.

Almost as if it is skipping over that camera taking step.

Im sure the solution to this is simple, I just have a baked brain right now and probably can't see the forest because of the trees. (if that is even how that analogy is said).

Do I run the camera part on another thread?

An idea I had was to use a boolean to check for the file's existence and size, but I am unsure how to make the program check that over and over again until it returns true.

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

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

发布评论

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

评论(1

情痴 2024-11-22 06:01:11

我猜测可能发生的情况是您的回调发生在单独的线程上。因此,您的“打开邮件客户端”操作是在您的图像仍在保存时发生的。您应该尝试的是使用某种标志来告诉您是否正在发送或保存。在打开相机之前在 onOptionsItemSelected 中设置此项。然后,在您的 mPictureCallback 中执行您的 ACTION_SEND 意图(或保存操作)

I'm guessing what might be happening is that your callback is occurring on a separate thread. So, your "open mail client" action is occurring while your image is still being saved. What you should try, is have a flag of some sort that tells you if you are doing a send or save. Set this in the onOptionsItemSelected before you open the camera.. Then, in your mPictureCallback have that perform your ACTION_SEND intent (or save action)

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