Android activity.getWindowManager().getDefaultDisplay().getRotation()始终为0

Android activity.getWindowManager().getDefaultDisplay().getRotation()始终为0,android,Android,我正在开发一个摄像头应用程序 但是在setCameraOrientation中,当我尝试获得显示旋转时,在rotation /**If you want to make the camera image show in the same orientation as the display, you can use the following code. */ public static void setCameraDisplayOrientation(Activity activity,

我正在开发一个摄像头应用程序 但是在
setCameraOrientation
中,当我尝试获得显示旋转时,在
rotation

/**If you want to make the camera image show in the same orientation as the display, you can use the following code.
*/
  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);
  }
在SurfaceChanged中调用此方法

Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if(display.getRotation() == Surface.ROTATION_0)
if(display.getRotation() == Surface.ROTATION_90)
if(display.getRotation() == Surface.ROTATION_180)
if(display.getRotation() == Surface.ROTATION_270)

如果自动旋转功能关闭,我的手机(三星J3 Prime)会发生这种情况。

@Prasanath S,我仍在进行旋转0@DeepanshuNamdeo尝试WindowManager WindowManager=(WindowManager)getSystemService(Context.WINDOW\u服务);int rotation=windowManager.getDefaultDisplay().getRotation()@Prasanath什么都没发生,还是0