title: Taking photo with camera, onActivityResult does not contains media (photo) uri
body: <p>Hi i started to use Camera in Android, as simple as it can get from <a href="http://developer.android.com/guide/topics/media/camera.html" rel="nofollow">here</a>.</p>
  
  <p>The problem is after i shoot the photo the file's uri is just null for some reason.</p>
  
  <p>Steps:</p>
  
  <ol>
  <li><p>I ran the <code>takePhoto()</code> func, my phone's standard camera app starts,
  i take a photo, i save it.</p></li>
  <li><p>My app ran the <code>onActivityResult(...)</code> func as it gets back the control from camera, and the file's uri is just null.</p></li>
  </ol>
  
  <p>Code:</p>
  
  <p>In my Activity:</p>
  
  <pre><code>/**
   * Intent code for capturing a photo
   */
  private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
  
  /**
   * 
   * Takes a photo
   */
  public void takePhoto() {
      // create Intent to take a picture and return control to the calling application
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      fileUri = CameraHelper.getOutputMediaFileUri(CameraHelper.MEDIA_TYPE_IMAGE); // create a file to save the image
      Log.i("PHOTO", "file uri is: " + fileUri.toString());
      intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
      // start the image capture Intent
      startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
  }
  /**
   * 
   * After taking the photo...
   */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
          if (resultCode == RESULT_OK) {
              // Image captured and saved to fileUri specified in the Intent
              if (data == null) {
                  Toast.makeText(this, "Camera error: data is null!", Toast.LENGTH_LONG).show();
                  Log.i("PHOTO", "Camera error: data is null!");
                  // Error is here, data does not contains the uri.
              }
              else {
                  Toast.makeText(this, "Image saved to:\n" + data.getData(), Toast.LENGTH_LONG).show();
                  Log.i("PHOTO", "Image saved to:\n" + data.getData());
              }
          }
          else if (resultCode == RESULT_CANCELED) {
              // User cancelled the image capture
          }
          else {
              // Image capture failed, advise user
          }
      }
  }
  </code></pre>
  
  <p>CameraHelper class:</p>
  
  <pre><code>public class CameraHelper {
  
  public static final int MEDIA_TYPE_IMAGE = 1;
  
  
  
  /** Create a file Uri for saving an image or video */
  public static Uri getOutputMediaFileUri(int type) {
      return Uri.fromFile(getOutputMediaFile(type));
  }
  /** Create a File for saving an image or video */
  private static File getOutputMediaFile(int type) {
      // To be safe, you should check that the SDCard is mounted
      // using Environment.getExternalStorageState() before doing this.
      File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp");
      // This location works best if you want the created images to be shared
      // between applications and persist after your app has been uninstalled.
      // Create the storage directory if it does not exist
      if (!mediaStorageDir.exists()) {
  
          Log.i("PHOTO", "directory is not exists yet!");
          if (!mediaStorageDir.mkdirs()) {
              Log.d("MyCameraApp", "failed to create directory");
              return null;
          }
          else {
              Log.i("PHOTO", "just made directory: " + mediaStorageDir.getAbsolutePath());
          }
      }
      else {
          Log.i("PHOTO", "directory is already exist: " + mediaStorageDir.getAbsolutePath());
      }
      // Create a media file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      File mediaFile;
      if (type == MEDIA_TYPE_IMAGE) {
          mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
      }
      else {
          return null;
      }
      return mediaFile;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Log output:</p>
  
  <pre><code>01-13 16:15:37.485: I/PHOTO(6818): directory is already exist: /storage/sdcard0/Pictures/MyCameraApp
  01-13 16:15:37.495: I/PHOTO(6818): file uri is: file:///storage/sdcard0/Pictures/MyCameraApp/IMG_20150113_161537.jpg
  
  
  01-13 16:16:13.482: I/PHOTO(6818): Camera error: data is null!
  </code></pre>
  
  <p>All the pictures are in the folder: <code>Pictures/MyCameraApp</code> but <code>onActivityResult(...)</code> does not contains the uri in the data field.</p>
  
  <p>What m i doing wrong?</p>