title: Android image orientation issue with custom camera activity
body: <p>I wrote a custom camera activity to handle some issues I've been having with certain android devices when calling intent image capture.  The user is able to either select save image or just use the data returned back from the <code>OnPictureTakenCallback</code>.</p>
  
  <p>The problem I'm having is displaying the image correctly with respect to the orientation it was taken. I force the activity to be displayed in portrait by calling <code>SetRequestedOrientation</code>.</p>
  
  <p>How would I know the correct Orientation the camera was in when the user took the picture?
  i.e. The user could take the picture at a rotation of 90 (portrait). </p>
  
  <p>I've tried to get to use the <code>getRotation()</code> on the window manager's default display, but with setting the requested orientation to portrait that only returns <code>Surface.ROTATION_0</code>.</p>
  
  <p>Update:
  To clarify my other issue, how could I determine the orientation from just the <code>byte[]</code> data in the picture callback if the user were to not save the image?</p>
  
  <p>Update: After trying the answers below with this code all I'm getting is ExifInterface.ORIENTATION_NORMAL. I've also changed my code to just save the file returned from the camera as I'm not sure there is an easy way to determine the orientation with just having the <code>byte[]</code> data.</p>
  
  <pre><code>    private PictureCallback mPicture = new PictureCallback() 
      {
          @Override
          public void onPictureTaken(byte[] data, Camera camera) 
          {
              File directory = new File(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES),
                      "MyApp");
              if(!directory.exists())
              {
                  if(!directory.mkdirs())
                  {
                      Log.d("CAMERA", "Unable to create directory to save photos.");
                      return;
                  }
              }
              File file = new File(directory.getPath() + file.separator + "IMG_" + SimpleDateFormat.getDateTimeInstance().toString() + ".jpg");
              FileOutputStream fos = new FileOutputStream(file);
              fos.write(data);
              fos.close();
              ExifInterface exif = new ExifInterface(file.getCanonicalPath());
              int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
              int rotate = 0;
  
              switch (orientation) 
              {
                  case ExifInterface.ORIENTATION_ROTATE_90:
                     rotate = 90;
                     break; 
                  case ExifInterface.ORIENTATION_ROTATE_180:
                     rotate = 180;
                     break;
                  case ExifInterface.ORIENTATION_ROTATE_270:
                     rotate = 270;
                     break;
                  case default:
                     break;
               }
          }
      };
  </code></pre>