相机应用无法恢复我的活动 [英] Camera app does not return to my activity

查看:82
本文介绍了相机应用无法恢复我的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想启动相机应用以获取照片,但是当我按下确定"按钮时,相机应用仍处于前景状态,并且我的活动无法恢复.

I want to launch the camera app to get a photo but when I press the ok button, the camera app is still in foreground, and my activity cannot resume.

这是我的工作:

    File file = new File(getFilesDir() + File.separator + UUID.randomUUID().toString() + ".jpg");
    try {
        file.createNewFile();
    } catch (IOException e) {
        Toast.makeText(this, R.string.problem_creating_file, Toast.LENGTH_LONG).show();
        return;
    }
    Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    takePhotoIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(takePhotoIntent, REQUEST_CODE_PHOTO);

在清单中:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

我在Internet上找到了很多解决方案,但是没有人为我工作((

I've found lots of solutions on Internet but no one worked for me :(

推荐答案

您正在启动第三方活动.没有人会强迫该活动的作者去做您想要的任何事情,包括:

You are launching a third-party activity. There is nobody forcing the authors of that activity to do anything that you seek, including:

  • 拍照
  • 将图片存储在您请求的位置
  • 拍照后立即返回您的应用

许多相机应用程序至少会执行其中的前两个操作.人们希望所有相机应用程序都能拍摄照片,但是可能至少有一个相机的ACTION_IMAGE_CAPTURE实现存在错误.

Many camera apps will do at least the first two of those things. One hopes that all camera apps would take a picture, but there's probably at least one out there with bugs in its ACTION_IMAGE_CAPTURE implementation.

因此,当您要求第三方应用程序拍照时,您和您的应用程序不得对第三方应用程序所做的任何假设.特别是,您需要注意,取决于用户选择的相机应用程序的实现,用户可能需要按BACK离开相机应用程序并返回到您的相机应用程序.而且,有故障的相机应用程序很可能甚至不遵守返回"按钮,在这种情况下,用户需要选择更好的相机应用程序.

Hence, you and your app must not make any assumptions about what the third-party app is doing when you ask it to take a picture. In particular, you need to be aware that the user may need to press BACK to leave the camera app and return to yours, depending upon the implementation of the user's chosen camera app. And it is entirely possible that a buggy camera app will not even honor the BACK button, in which case the user needs to choose a better camera app.

这篇关于相机应用无法恢复我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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