title: How to get uri of captured photo?
body: <p>What do I want to achieve? 
  I want to get URI of the captured image and save it on Firebase. 
  What did I try? 
  First of all I needed to open the camera. Below how I did it: </p>
  
  <pre><code> Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null)
          startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
  </code></pre>
  
  <p>After capturing the image, I needed to get the URI of the image. Below how I did it: </p>
  
  <pre><code>if (resultCode == Activity.RESULT_OK) {
          if (requestCode == CAMERA_REQUEST_CODE) {
              if (data != null) {
                  if (data.getData() != null) {
                     Uri capturedImageUri = data.getData(); 
                  } else {
                      Toast.makeText(getContext(), getString(R.string.coudldnt_get_photo), Toast.LENGTH_SHORT).show();
                  }
              } else {
                  Toast.makeText(getContext(), getString(R.string.coudldnt_get_photo), Toast.LENGTH_SHORT).show();
              }
  </code></pre>
  
  <p>So everything was OK. But only on some devices. I suppose that it works only on API level more than 21 devices. In other devices , <code>getData()</code> returns null. </p>
  
  <p>So, what I have done next? 
  I found that I can get Bitmap of the image through following code: </p>
  
  <pre><code>Bitmap bitmap = (Bitmap)data.getExtras().get("data") ; 
  </code></pre>
  
  <p>So, I have a bitmap of the image. And I needed to get the URI of this image. Below how I did it: </p>
  
  <pre><code>public Uri getImageUri(Context inContext, Bitmap inImage) {
    String path = 
    Images.Media.insertImage(inContext.getContentResolver(), inImage, 
    "Title", null);
    return Uri.parse(path);
   } 
  </code></pre>
  
  <p>Above code returns me URI, but the image has really bad quality.</p>
  
  <p>So, I kept looking for a solution. And found that the right way is to create the file when I start the <code>CameraActivity</code> and save the uri of that file. And <code>onActivityResult</code> I tried to get that uri. Below how I did it: </p>
  
  <pre><code>Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
      if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {
          File photoFile = null;
          try {
              photoFile = createImageFile();
          } catch (IOException ex) {
  
          }
          if (photoFile != null) {
              Uri photoUri = FileProvider.getUriForFile(getContext(), "i_dont_know_what_to_write_here", photoFile);
              cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
              startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
          }
  
      }
  </code></pre>
  
  <p>And my <code>onActivityResult</code> became: </p>
  
  <pre><code>    if (resultCode == Activity.RESULT_OK) {
      if (requestCode == CAMERA_REQUEST_CODE) {
          if (data != null) {
   Uri capturedPhotoUri = 
   data.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
     } else {
     Toast.makeText(getContext(), 
     getString(R.string.coudldnt_get_photo), Toast.LENGTH_SHORT).show();
              }
  </code></pre>
  
  <p>The above concept requires to add some tags on manifest :</p>
  
  <pre><code> &lt;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="i_dont_know_what_to_write_here"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/my_paths" /&gt;
          &lt;/provider&gt;
  </code></pre>
  
  <p>My xml file is : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;paths&gt;
  &lt;external-files-path name="images"/&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>The above method didn't work because <code>data</code> on <code>onActivityReuslt</code> was null.</p>
  
  <p>So, what I need to do in order to achieve my goal? </p>