title: Uri returned in camera intent is null
body: <p>I am trying to create and Android application that takes a photo or uploads a photo to the server. My main objective is to get the URI of the photo which is returned in the intent. I have followed the steps from [1].
  The problem is that on a phone with Lollipop, version 5.1.1 it works fine and the intent returns the URI of the photo, but on a phone which has Jelly Bean, version 4.2.1, the URI returned in the intent is null.</p>
  
  <p>Here is my code</p>
  
  <p><strong>Create View and set listeners to buttons</strong></p>
  
  <pre><code>static final int REQUEST_TAKE_PHOTO = 1;
  static final int REQUEST_GET_PHOTO = 2;   
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_home_page, container, false);
  
      camera = (FloatingActionButton) view.findViewById(R.id.take_photo);
      upload = (FloatingActionButton) view.findViewById(R.id.upload_photo);
      photo = (ImageView) view.findViewById(R.id.photo);
  
      camera.setOnClickListener(takePhoto);
      upload.setOnClickListener(uploadPhoto);
  
      return view;
  }
  </code></pre>
  
  <p><strong>Take Picture Action</strong></p>
  
  <pre><code>   View.OnClickListener takePhoto = new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                  startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
              }
          }
      };
  </code></pre>
  
  <p><strong>Upload from gallery listener</strong></p>
  
  <pre><code>View.OnClickListener uploadPhoto = new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
          if (photoPickerIntent.resolveActivity(getActivity().getPackageManager()) != null) {
              photoPickerIntent.setType("image/*");
              startActivityForResult(photoPickerIntent, REQUEST_GET_PHOTO);
          }
      }
  };
  </code></pre>
  
  <p><strong>Handle Intent Result</strong></p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
  
      if (resultCode == Activity.RESULT_OK &amp;&amp; (requestCode == REQUEST_TAKE_PHOTO || requestCode == REQUEST_GET_PHOTO)) {
  
          Uri imageUri = data.getData();
  
          try {
              Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getApplicationContext().getContentResolver(), imageUri);
              String filePath = getPath(imageUri);
              bitmap = BitmapRotator.rotateBitmap(bitmap, filePath);
  
              photo.setImageBitmap(bitmap);
              UploadPhotoController.uploadPhoto(filePath);
  
          } catch (IOException e) {
              e.printStackTrace();
          } catch (PhotoNotFoundException e) {
              e.printStackTrace();
          } catch (NullPointerException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>data.getData() is null thus I can't get the uri, or the file path of the image.</p>
  
  <p>Thank you.</p>
  
  <p>[1] <a href="http://developer.android.com/training/camera/photobasics.html" rel="nofollow">http://developer.android.com/training/camera/photobasics.html</a></p>