按下 OK 按钮后默认相机活动未完成 [英] Default Camera Activity Not Finishing Upon OK button press

查看:13
本文介绍了按下 OK 按钮后默认相机活动未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的活动中调用默认摄像头,然后处理 onActivityResult.我的代码似乎在 LG Ally 上运行良好,拍照时没有确认.但是,当我在 Nexus S 上运行相同的应用程序时,它会在返回我的活动之前提示我Ok"、Retake"或Cancel".虽然取消"有效,返回我的活动而不保存图片,确定"似乎没有任何效果,甚至没有返回我的活动.

I'm calling the default camera from my activity and then handling the onActivityResult. My code seems to work fine on the LG Ally which doesn't have a confirmation when a picture is taken. However, when I run the same app on the Nexus S, it prompts me with an "Ok", "Retake", or "Cancel" before returning to my activity. While "Cancel" works, returning to my activity without saving the picture, "Ok" doesn't seem to have any effect, not even returning to my activity.

我的代码如下:

private void captureImage() {

    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File path = new File(Environment.getExternalStorageDirectory().getPath() + "/Images/" + (new UserContextAdapter(this)).getUser() + "/");
        path.mkdirs();
        File file = new File(path, "Image_Story_" + mRowId.toString() + ".jpg");

        newImageUri = Uri.fromFile(file);

        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, newImageUri);

        startActivityForResult(intent, CAPTURE_IMAGE);
    }

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    switch (requestCode) {
    case CAPTURE_IMAGE:
        switch (resultCode ) {
        case 0:
            Log.i("CAPTURE", "Cancelled by User");
            break;
        case -1:
            mImageUri = newImageUri;
            setImageFromUri();
            }
    }

推荐答案

我想我只是遇到了完全相同的问题.

I think I just had the exact same problem.

如果保存图片的路径不正确,相机将不会返回您的应用.一旦我确定目录存在,一切正常.确保目录存在,然后它应该可以工作.

If the path to save the picture isn't correct, the camera won't return to your app. Once I made sure the directory exists, everything worked fine. Make sure the directory exists, then it should work.

-- 编辑--

我刚刚看到,您调用 path.mkdirs(); 但我认为它不起作用.正如您在 android 文档中所读到的请注意,此方法在失败时不会抛出 IOException.调用者必须检查返回值.".请务必检查该目录是否真的存在.

I just saw, that you call path.mkdirs(); but I think that it doesn't work. As you can read in the android doc "Note that this method does not throw IOException on failure. Callers must check the return value.". Please be sure to check if the directory really exists.

这篇关于按下 OK 按钮后默认相机活动未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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