title: ExifInterface got an unsupported image
body: <p>I have used <code>ExifInterface</code> in an Android app for obtaining camera orientation  of an image. My code works perfectly for <code>Build.VERSION.SDK_INT &lt; 24</code>. But when build version is greater or equal to 24 it gives warning in android studio logcat and does not work properly.</p>
  
  <p>Here is my code block from onActivityResult method:</p>
  
  <pre><code>if(requestCode == REQUEST_CAPTURE_IMG &amp;&amp; resultCode == RESULT_OK) {
              Log.d(TAG, "Inside camera operation");
              int reqWidth = 480, reqHeight = 800;
              try {
                  InputStream inStream = null;
                  try {
                      inStream = getContentResolver().openInputStream(imageUri);
  
                      //Decode image size
                      BitmapFactory.Options options = new BitmapFactory.Options();
                      options.inJustDecodeBounds = true;
  
                      BitmapFactory.decodeStream(inStream, null, options);
                      inStream.close();
  
                      options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
  
                      options.inJustDecodeBounds = false;
                      inStream = getContentResolver().openInputStream(imageUri);
  
                      CommonStaticClass.mImage = BitmapFactory.decodeStream(inStream, null, options);
  
                      ExifInterface exif = null;
  
                      try {
                          //File pictureFile = new File(imgDecodableString);
                          if (Build.VERSION.SDK_INT &gt;= 24) {
                              exif = new ExifInterface(inStream);
                              Log.d("exif", "sdk 24");
                          }
                          else {
                              exif = new ExifInterface(imageUri.getPath());
                          }
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
  
                      int orientation = ExifInterface.ORIENTATION_NORMAL;
  
                      if (exif != null)
                          orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  
                      switch (orientation) {
                          case ExifInterface.ORIENTATION_ROTATE_90:
                              CommonStaticClass.mImage = rotateBitmap(CommonStaticClass.mImage, 90);
                              break;
                          case ExifInterface.ORIENTATION_ROTATE_180:
                              CommonStaticClass.mImage = rotateBitmap(CommonStaticClass.mImage, 180);
                              break;
  
                          case ExifInterface.ORIENTATION_ROTATE_270:
                              CommonStaticClass.mImage = rotateBitmap(CommonStaticClass.mImage, 270);
                              break;
                      }
  
                      inStream.close();
                  } catch (IOException e) {
                      //Toast.makeText(this, "IO exception", Toast.LENGTH_SHORT).show();
                      Toast.makeText(this, SelectSuitActivity.this.getString(R.string.wrong_msg), Toast.LENGTH_SHORT).show();
                  }
                  //CommonStaticClass.mImage = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
                  startActivity(intent);
              } catch (Exception e) {
                  Toast.makeText(this, SelectSuitActivity.this.getString(R.string.wrong_msg), Toast.LENGTH_SHORT).show();
              }
          }
  </code></pre>
  
  <p>And here is the logcat result when I pick image from camera:</p>
  
  <pre><code>    10-19 12:39:04.399 2912-2912/com.example.myapp I/ExifInterface_JNI: Corrupted image.
      10-19 12:39:04.414 2912-2912/com.example.myapp W/ExifInterface: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
      java.io.EOFException
      at java.io.DataInputStream.readByte(DataInputStream.java:270)
      at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1834)
      at android.media.ExifInterface.loadAttributes(ExifInterface.java:1475)
      at android.media.ExifInterface.&lt;init&gt;(ExifInterface.java:1174)
      at com.lostsym.founder.SelectSuitActivity.onActivityResult(SelectSuitActivity.java:621)
      at android.app.Activity.dispatchActivityResult(Activity.java:6932)
      at android.app.ActivityThread.deliverResults(ActivityThread.java:4085)
      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
      at android.app.ActivityThread.-wrap20(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6119)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>
  
  <p>It would be helpful if anyone can figure out what's wrong here. Thank you.</p>