title: android getContentResolver().insert() occasionally returning null
body: <p>I have a piece of code that aims to launch the android camera, let the user take a photo and eventually keep the uri of the image once it is saved.</p>
  
  <p>So far I have managed to get it working. However, it seems like a 50/50 chance that the app will crash with a NPE. I have no idea why this is happening</p>
  
  <p>my code:</p>
  
  <pre><code>private Uri mImageCaptureUri;
  
  private void doTakePhotoAction() {
          String fileName = "temp.jpg";  
          ContentValues values = new ContentValues();  
          values.put(MediaStore.Images.Media.TITLE, fileName);  
          mImageCaptureUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
  
          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
          intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);  
          startActivityForResult(intent, PICK_FROM_CAMERA);
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode != RESULT_OK) {
          return;
      }
  
      switch (requestCode) {
      case PICK_FROM_CAMERA:
          String[] projection = { MediaStore.Images.Media.DATA}; 
          Cursor cursor = managedQuery(mImageCaptureUri, projection, null, null, null); 
          int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
          cursor.moveToFirst(); 
          String capturedImageFilePath = cursor.getString(column_index_data);
          Intent intent = new Intent(this, CropImage.class);
          intent.putExtra("image-path", capturedImageFilePath);
          intent.putExtra("scale", true);
          startActivity(intent);
          break;
      }
  }
  </code></pre>
  
  <p>The NPE error refers me back to the line </p>
  
  <pre><code>Cursor cursor = managedQuery(mImageCaptureUri, projection, null, null, null); 
  </code></pre>
  
  <p>and it is being thrown because <code>mImageCaptureUri</code> is null. Does anyone have any ideas on how to fix / work around this or why this is in fact happening</p>