1

I have an activity where click of button camera activity is launched . Sometimes onActivityResult is called and sometimes not . Even after restarting the device the onActivityResult is not called nor does it restart the current activity . Any solution to this weird behavior ?

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        String imageUri = data.toURI();
        Uri uri = Uri.parse(imageUri);
        try {
            mBitmap = Media.getBitmap(getContentResolver(), uri);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // if result is ok returns the bitmap
        // mBitmap = (Bitmap) data.getExtras().get("data");
        mImageView.setImageBitmap(mBitmap);
        new Thread(postTheImage).start();
    } else {
        Toast.makeText(getApplicationContext(), "Error during capturing the image", Toast.LENGTH_SHORT).show();
    }
}

@Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.getId() == R.id.capture_image_button) {
            // Open the camera to capture the image
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    }
Preethi
  • 2,112
  • 7
  • 38
  • 54

1 Answers1

0

You are not providing the camera activity with the information it requires. You need to supply it a file URI.

Please refer to the following

onActivityResult returned from a camera, Intent null

Community
  • 1
  • 1
Pork 'n' Bunny
  • 6,740
  • 5
  • 25
  • 32
  • 3
    This answer is not correct. You don't need to supply a file URI. In general OP's code should work just fine. You can request the camera to take a photo. It will return a thumbnail of the photo in the `Intent` parameter to `onActivityResult()`. The linked question has unfortunately not been properly answered :-( – David Wasser Oct 18 '13 at 15:59