因此,经过一段时间弄乱相机后,我终于得到了实际的相机方向:
private 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);
}
但是,状态栏(顶部带有时间和网络信息的东西)仍处于格局中。 我已经包含了这个:
android:screenOrientation="portrait"
在我的AndroidManifest.xml中 关于如何解决这个问题的任何想法?
答案 0 :(得分:0)
如果您知道要设置的方向,可以在setRequestedOrientation(int requestedOrientation)
Activity