i_me_mine
i_me_mine

Reputation: 1433

result_ok for camera returning 0

I'm launching a camera ActivityForResult and my resultCode is coming back as 0 and my requestCode is coming back as -1. The funny thing is this was working before I used resultCode. Allow me to show you

private class ClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, CAMERA);
        }    
    }

    public void onActivityResult(int resultCode, int requestCode, Intent data) {

        if (requestCode == CAMERA) {                
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");
            MediaStore.Images.Media.insertImage(getActivity()
            .getContentResolver(), bmp, "picture", "a picture");
            Log.v("HEY", "Your image should be in the gallery now");
        }    
    }

However I obviously need to add some code in case the user presses cancel instead of snapping the photo. So I added some code and my new onActivityResult looks like this

public void onActivityResult(int resultCode, int requestCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.v("RESULT CODE", "" + resultCode);
        Log.v("REQUEST CODE", "" + requestCode);
        if (requestCode == CAMERA) {

            if (resultCode == Activity.RESULT_OK) {
                Bundle extras = data.getExtras();
                bmp = (Bitmap) extras.get("data");
                MediaStore.Images.Media.insertImage(getActivity()
                        .getContentResolver(), bmp, "picture", "a picture");
                Log.v("HEY", "Your image should be in the gallery now");
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.v("CANCELED", "The user has canceled the activity");
            }
        }

    }

Not only does it not work my logcat says

06-13 20:53:36.320: V/RESULT CODE(6140): 0
06-13 20:53:36.320: V/REQUEST CODE(6140): -1

Why is this happening? Anyone run into this before?

Upvotes: 0

Views: 1010

Answers (1)

Aprian
Aprian

Reputation: 1728

This is the correct onActivityResult and the cause of your problem:

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

VS yours:

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

Upvotes: 3

Related Questions