默认摄像头的活动没有完成经确定按钮preSS [英] Default Camera Activity Not Finishing Upon OK button press

查看:122
本文介绍了默认摄像头的活动没有完成经确定按钮preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话从我的活动中默认的摄像头,然后处理onActivityResult。我的code似乎做工精细,LG的盟友不具有确认时拍摄照片。然而,当我运行的Nexus S在同一个应用程序,它提示我有一个好,重拍,或返回到我的活动之前,取消。尽管取消的作品,回到我的活动不保存图片,确定似乎没有产生任何影响,甚至没有回到我的活动。

我的$ C $低于C:

 私人无效captureImage(){

    字符串状态= Environment.getExternalStorageState();
    如果(Environment.MEDIA_MOUNTED.equals(州)){
        文件路径=新的文件(Environment.getExternalStorageDirectory()getPath()+/图片/+(新UserContextAdapter(本))的getUser()+/);
        path.mkdirs();
        档案文件=新的文件(路径,Image_Story_+ mRowId.toString()+.JPG);

        newImageUri = Uri.fromFile(文件);

        意向意图=新的意图(android.provider.MediaStore.ACTION_IM​​AGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT,newImageUri);

        startActivityForResult(意向,CAPTURE_IMAGE);
    }

}

@覆盖
公共无效onActivityResult(INT申请code,INT结果code,意图意图){

    开关(要求code){
    案例CAPTURE_IMAGE:
        开关(结果code){
        情况下0:
            Log.i(捕捉,由用户取消);
            打破;
        情况1:
            mImageUri = newImageUri;
            setImageFromUri();
            }
    }
 

解决方案

我想我只是有相同的问题。

如果保存图片的路径是不正确的,相机将不会返回到你的应用程序。一旦我确定目录存在,一切正常。确保该目录存在,比它应该工作。

- 编辑 -

我刚刚看到,那你叫 path.mkdirs(); ,但我认为这是行不通的。正如你可以在Android文档阅读注意,此方法不抛出IOException失败。调用者必须检查返回值。请一定要检查如果目录确实存在。

心连心

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.

My code below:

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, than it should work.

-- Edit --

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.

hth

这篇关于默认摄像头的活动没有完成经确定按钮preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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