Search code examples
androidandroid-fragmentsandroid-cameraandroid-camera-intent

Capture Image from Fragment


I need to capture an image from the camera and I need to do it from inside a Fragment. My problem is that onActivityResult is never called. Below is my code:

private void dispatchTakePictureIntent(){
  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
  }



@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
  if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
     Bundle extras = data.getExtras();
     Bitmap imageBitmap = (Bitmap) extras.get("data");
     im.setImageBitmap(imageBitmap);
  }
  Log.e(TAG,"hello");
  super.onActivityResult(requestCode, resultCode, data);
}

I have looked up several threads here on this forum but none of them are working for me.


Solution

  • Check if you aren't overwriting onActivityResult in your Activity. If so you should call super.onActivityResult from this method. Follow this question to find out the details: onActivityResult is not being called in Fragment