Aaron Decker
Aaron Decker

Reputation: 558

ACTION_IMAGE_CAPTURE doesn't call onActivityResult?

My onCreate():

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


         Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            imageFile = new File(Environment.getExternalStorageDirectory(),
                    "/image.jpg");

            System.out.println(imageFile +" is the path with extentions");
            outputFileUri = Uri.fromFile(imageFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, TAKE_PICTURE);

        setContentView(R.layout.activity_head_size);

System.out.println("OnCreate");
    }

Obviously, that starts the camera and waits for it to finish and return the image. When that finishes, it should call

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        }

However, after I hit save in the camera, it loads the onCreate and reruns the camera. Then If you retake the image and hit save it goes to the activity; however, doesn't run the onActivityResult? what is going on?

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(resultCode == 1){
            myImage = (ImageView) findViewById(R.id.imageView1);


            myBitmap = BitmapFactory.decodeFile( Environment.getExternalStorageDirectory() +
                   "/image.jpg");



             myBitmap = Bitmap.createScaledBitmap(myBitmap, 256, 256, false);
                myImage.setImageBitmap(myBitmap);

                width = myBitmap.getWidth();
                height = myBitmap.getHeight();


                orig = new int[width*height];

                myBitmap.getPixels(orig, 0, width, 0, 0, width, height);

                System.out.println("ready for processing");
            }
        }

Upvotes: 0

Views: 1088

Answers (1)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39718

Use the enum value, instead of just a hard coded int.

if(resultCode == RESULT_OK){

From the docs, RESULT_OK=-1, and you were looking for 1. Also, I don't see where you are checking for the requestCode==TAKE_PICTURE, that should be a pre-request as well, to ensure you are responding to the right intent.

Upvotes: 1

Related Questions