title: Camera activity returning null android
body: <p>I am building an application where I want to capture an image by the default camera activity and return back to my activity and load that image in a ImageView. The problem is camera activity always returning null. In my <code>onActivityResult(int requestCode, int resultCode, Intent data)</code> method I am getting data as <code>null</code>. Here is my code:</p>
  
  <pre><code>public class CameraCapture extends Activity {
  
      protected boolean _taken = true;
      File sdImageMainDirectory;
      Uri outputFileUri;
  
      protected static final String PHOTO_TAKEN = "photo_taken";
      private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          try {
  
              super.onCreate(savedInstanceState);   
              setContentView(R.layout.cameracapturedimage);
                      File root = new File(Environment
                              .getExternalStorageDirectory()
                              + File.separator + "myDir" + File.separator);
                      root.mkdirs();
                      sdImageMainDirectory = new File(root, "myPicName");
  
  
  
                  startCameraActivity();
  
          } catch (Exception e) {
              finish();
              Toast.makeText(this, "Error occured. Please try again later.",
                      Toast.LENGTH_SHORT).show();
          }
  
      }
  
      protected void startCameraActivity() {
  
          outputFileUri = Uri.fromFile(sdImageMainDirectory);
  
          Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
          intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
  
          startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
          switch (requestCode) {
          case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE:
          {
              if(resultCode==Activity.RESULT_OK)
              {
                  try{
                  ImageView imageView=(ImageView)findViewById(R.id.cameraImage);
                  imageView.setImageBitmap((Bitmap) data.getExtras().get("data"));
                  }
                  catch (Exception e) {
                      // TODO: handle exception
                  }
              }
  
              break;
          }
  
          default:
              break;
          }
      }
  
       @Override
      protected void onRestoreInstanceState(Bundle savedInstanceState) {
          if (savedInstanceState.getBoolean(CameraCapture.PHOTO_TAKEN)) {
              _taken = true;
          }
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          outState.putBoolean(CameraCapture.PHOTO_TAKEN, _taken);
      }
  }
  </code></pre>
  
  <p>Am I doing anything wrong?</p>