title: Why does an image captured using camera intent gets rotated on some devices on Android?
body: <p>I'm capturing an image and setting it to image view.</p>
  
  <pre><code>public void captureImage() {
  
      Intent intentCamera = new Intent("android.media.action.IMAGE_CAPTURE");
      File filePhoto = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
      imageUri = Uri.fromFile(filePhoto);
      MyApplicationGlobal.imageUri = imageUri.getPath();
      intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
      startActivityForResult(intentCamera, TAKE_PICTURE);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent intentFromCamera) {
      super.onActivityResult(requestCode, resultCode, intentFromCamera);
  
      if (resultCode == RESULT_OK &amp;&amp; requestCode == TAKE_PICTURE) {
  
          if (intentFromCamera != null) {
              Bundle extras = intentFromCamera.getExtras();
              if (extras.containsKey("data")) {
                  bitmap = (Bitmap) extras.get("data");
              }
              else {
                  bitmap = getBitmapFromUri();
              }
          }
          else {
              bitmap = getBitmapFromUri();
          }
          // imageView.setImageBitmap(bitmap);
          imageView.setImageURI(imageUri);
      }
      else {
      }
  }
  
  public Bitmap getBitmapFromUri() {
  
      getContentResolver().notifyChange(imageUri, null);
      ContentResolver cr = getContentResolver();
      Bitmap bitmap;
  
      try {
          bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, imageUri);
          return bitmap;
      }
      catch (Exception e) {
          e.printStackTrace();
          return null;
      }
  }
  </code></pre>
  
  <p>But the problem is, the image on some devices every time it gets rotated. For example, on a Samsung device it works good, but on a <a href="https://en.wikipedia.org/wiki/Sony_Xperia">Sony Xperia</a> the image gets rotated by 90 degrees and on <a href="https://en.wikipedia.org/wiki/Toshiba_Thrive">Toshiba Thrive</a> (tablet) by 180 degrees.</p>