title: Pick a photo or take a photo and use onActivityResult() for both not working
body: <p>I'm trying to create an app were i can either take a new photo or use an existing one. I get both functions to work separatly but not together. The application crash when the <code>Uri imageUri = data.getData();</code> runs.</p>
  
  <p>Here is the code:</p>
  
  <pre><code> public void btnPhotoClicked(View v) {
  
      //Use to invoke a Camera
      Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      //Create a variable with the filepath generated by the android operating system, Like a baws
  
      File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
      if (pictureDirectory.exists()) {
          File test1 = new File(pictureDirectory, "100MEDIA/");
          if (test1.exists()) {
              pictureDirectory = test1;
          } else {
              File test2 = new File(pictureDirectory, "100ANDRO/");
              if (test2.exists()) {
                  pictureDirectory = test2;
              } else {
                  File test3 = new File(pictureDirectory, "Camera/");
                  if (!test3.exists()) {
                      test3.mkdirs();
                  }
                  pictureDirectory = test3;
              }
          }
      } else {
          pictureDirectory = new File(pictureDirectory, "Camera/");
          pictureDirectory.mkdirs();
      }
  
      String pictureName = getPictureName();
      File imageFile = new File(pictureDirectory, pictureName);
      Uri pictureUri = Uri.fromFile(imageFile);
      cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
  
  
      //Start intent and anticipate result
      startActivityForResult(cameraIntent, CAMERA_RESULT);
  }
  </code></pre>
  
  <p>and here is the code for the <code>protected void onActivityResult(int requestCode, int resultCode, Intent data)</code></p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  
  if (resultCode == RESULT_OK) {
      //if we are here everything processed successfully
  
      if (requestCode==IMAGE_GALLERY_REQUEST) {
          //If we are here we came from the Välj existerande build
          Log.d("MainActivity", data.toString());
          Toast.makeText(this, "IMAGE GALLERY_REQUEST", Toast.LENGTH_LONG).show();
          //the address of the image on the device SD-card
          Uri imageUri = data.getData();
  
          //Declare a stream to read the image data from the SD-card
          InputStream inputStream;
  
          //Getting a Input stream based upon the image uri
          try {
              //if it execute flawlessly
              inputStream = getContentResolver().openInputStream(imageUri);
  
              Bitmap image = BitmapFactory.decodeStream(inputStream);
  
              //show the image to the user
  
              mImageView.setImageBitmap(image);
  
          } catch (FileNotFoundException e) {
              //show massage saying if the image is unavailable
              Toast.makeText(this, "Could not open image", Toast.LENGTH_LONG).show();
          }
  
      } else if (requestCode == CAMERA_RESULT) {
          //We are here because we have received a result from the camera
          Toast.makeText(this, "CAMERA RESULT", Toast.LENGTH_LONG).show();
          Log.d("MainActivity", data.toString());
          //the address of the image on the device SD-card
          Uri imageUri = data.getData();
  
          //Declare a stream to read the image data from the SD-card
          InputStream inputStream;
  
          //Getting a Input stream based upon the image uri
          try {
              //if it execute flawlessly
              inputStream = getContentResolver().openInputStream(imageUri);
  
              Bitmap image = BitmapFactory.decodeStream(inputStream);
              //show the image to the user
  
              mImageView.setImageBitmap(image);
  
          } catch (FileNotFoundException e) {
              //show massage saying if the image is unavailable
              Toast.makeText(this, "Could not open image", Toast.LENGTH_LONG).show();
          }
  
  
  
      }
  
  }
  </code></pre>