当我没有升级到4.4.2时,支持前置摄像头,屏幕以横向模式打开,但是当我升级到最新版本时,相机不支持前置模式,并且它正在旋转到纵向模式。
我打开相机的源代码如下:
private void getPhotoFromCamera()
{
try
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extras.CAMERA_FACING",1);
VisitorRegistrationFragment.this.startActivityForResult(intent,FROM_CAMERA);
}
catch (Exception e)
{
e.printStackTrace();
}
catch (OutOfMemoryError e)
{
e.printStackTrace();
}
}
有谁可以帮我解决如何打开前置摄像头以及如何限制摄像头仅在横向模式下打开?
答案 0 :(得分:0)
您可以尝试将方向放在意图中:
$scope.$broadcast('scroll.resize');
如果您在Manifest中设置活动,请添加:
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
答案 1 :(得分:-1)
只需在横向模式中定义您的活动
即可android:screenOrientation="landscape"
并在代码下面打开前置摄像头
private Camera openFrontFacingCameraGingerbread() {
int cameraCount = 0;
Camera cam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
try {
cam = Camera.open(camIdx);
} catch (RuntimeException e) {
Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
}
}
}
return cam;
}
参考链接How do I open the "front camera" on the Android platform?