title: Get uri of picture taken by camera
body: <p>When the user takes a picture with the camera, I want the image displayed in an ImageView and I want to save the Uri to an online database. I heard saving the Uri of a picture is better than saving the path.</p>
  
  <p>So this is how I start the camera:</p>
  
  <pre><code>intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getFile(getActivity()))); 
  String a = String.valueOf(Uri.fromFile(getFile(getActivity())));
  intent.putExtra("photo_uri", a);
  startActivityForResult(intent, PICK_FROM_CAMERA);
  </code></pre>
  
  <p>where</p>
  
  <pre><code>private File getFile(Context context){
    File sdCard = Environment.getExternalStorageDirectory();
    File directory = new File (sdCard.getAbsolutePath() + "/Myapp");
    if (!directory.exists()) {
         directory.mkdirs();
    }
    String filename = "bl" + System.currentTimeMillis() + ".jpg";
    File newFile = new File(directory, filename);
  
    return newFile;
  }
  </code></pre>
  
  <p>In onActivityResult:</p>
  
  <pre><code>Bundle extras = data.getExtras();
  String photo_uri = extras.getString("photo_uri"); //null
  </code></pre>
  
  <p>This is always null. Btw before sending the intent the Uri looks like file://... instead of content:// which is the uri when I open an image from the gallery. I don't know if that's a problem.</p>
  
  <p>Also, should I save the path instead of the Uri to the database? I read that the Uri can be complicated in certain phones or Android versions. When I let the user select an image from the gallery, I save the Uri to the database, so I think the best way is saving the Uri in this case as well.</p>
  
  <p>I tried out many variations, but I get null every time I try to pass a variable with the intent...</p>