title: Image in gallery is saved with wrong orientation
body: <p><br>
  To take a photo I'm using the camera installed on the device.
  The photo is saved inside the gallery but is <strong>always saved horizontally</strong>.
  <br> How do I fix it? <br></p>
  
  <p><strong>This is the intent when click on the button "add photo":</strong></p>
  
  <pre><code> private void dispatchTakePictureIntent() {
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          // Ensure that there's a camera activity to handle the intent
          if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
              // Create the File where the photo should go
              File photoFile = null;
              try {
                  photoFile = createImageFile();
              } catch (IOException ex) {
                  // Error occurred while creating the File
                  ex.printStackTrace();
              }
              // Continue only if the File was successfully created
              if (photoFile != null) {
                  Uri photoURI = null;
                  photoURI = galleryAddPic();
                  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                  startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
              }
          }
      }
  </code></pre>
  
  <p><strong>This is the method <code>createImageFile()</code>:</strong></p>
  
  <pre><code>private File createImageFile() throws IOException {
          // Create an image file name
          String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
          imageFileName = "JPG_" + timeStamp + "_";
          File storageDir = Environment.getExternalStoragePublicDirectory(
                  Environment.DIRECTORY_PICTURES);
          File image = File.createTempFile(
                  imageFileName,  /* prefix */
                  ".jpg",         /* suffix */
                  storageDir      /* directory */
          );
  </code></pre>
  
  <p><strong>In the end, this is the method <code>galleryAddPic()</code>:</strong></p>
  
  <pre><code>private Uri galleryAddPic(){
          Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
          File f = new File(mCurrentPhotoPath);
          Uri contentUri = Uri.fromFile(f);
          mediaScanIntent.setData(contentUri);
          this.sendBroadcast(mediaScanIntent);
          return contentUri;
      }
          // Save a file: path for use with ACTION_VIEW intents
          mCurrentPhotoPath = image.getAbsolutePath();
          return image;
      }
  </code></pre>
  
  <p>After inserting the photo into the gallery, I can rotate the image as I want it.
  But in the gallery the image is not rotated well.<br>
  So I would like to save the image in the gallery with the right orientation. <br>
  Thanks!</p>