Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

android - Default Camera Activity Not Finishing Upon OK button press

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();
            }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

-- 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...