title: Rotate built in camera
body: <p>I've searched for the web but couldn't find a specific answer. I am using the built in camera-app in the phone and after I have recorded the orientation is 90 degress wrong. I think it is in the camera, because when I record it is always in landscape mode, but I want it to be rotate as the user rotates the phone. But when I use the Camera App normally i rotatates as it should. I tried with the <code>setCameraDisplayOrientation</code> method but I do not know how to use it.</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.content.pm.ActivityInfo;
  import android.hardware.Camera;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.Surface;
  import android.widget.Toast;
  
  public class CaptureVideo extends Activity {
  
      final static int REQUEST_VIDEO_CAPTURED = 1;
      static Uri uriVideo = null;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);// Nu kommer man till main.xml två gånger. Låter det ligga så så att vi connectar till en annan knapp senare. 
          Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
          intent.putExtra("android.intent.extra.durationLimit", 8);
          intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
          intent.putExtra("android.intent.extra.videoQuality", 1);
          startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
  
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(resultCode == RESULT_OK){
              if(requestCode == REQUEST_VIDEO_CAPTURED){
                  uriVideo = data.getData();
                  Toast.makeText(CaptureVideo.this,uriVideo.getPath(),Toast.LENGTH_LONG).show();
                  Intent intent = new Intent(CaptureVideo.this, ShowVideo.class);
                  startActivity(intent);
              }
          }
          else if(resultCode == RESULT_CANCELED){
              uriVideo = null;
              Toast.makeText(CaptureVideo.this,"Cancelled!",Toast.LENGTH_LONG).show();
          }
  
      }
      public static void setCameraDisplayOrientation(Activity activity,
               int cameraId, android.hardware.Camera camera) {
         android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
         android.hardware.Camera.getCameraInfo(cameraId, info);
         int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
         int degrees = 0;
         switch (rotation) {
               case Surface.ROTATION_0: degrees = 0; break;
               case Surface.ROTATION_90: degrees = 90; break;
               case Surface.ROTATION_180: degrees = 180; break;
               case Surface.ROTATION_270: degrees = 270; break;
         }
  
         int result;
         if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
             result = (info.orientation + degrees) % 360;
             result = (360 - result) % 360;  // compensate the mirror
         } else {  // back-facing
             result = (info.orientation - degrees + 360) % 360;
         }
         camera.setDisplayOrientation(result);
      }
  }
  </code></pre>