按下按钮,我试图在后置摄像头和前置摄像头之间切换。但是当我尝试切换到前置摄像头时,它无法打开并调用onCameraFail()
。
然而,这只发生在第一次按下。
它可以在任何后续印刷机上正常工作。
private CameraFragment bfc, ffc, current;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
bfc = (CameraFragment) getSupportFragmentManager()
.findFragmentById(R.id.camera_preview);
if (Camera.getNumberOfCameras() > 1) {
ffc = new CustomCameraFragment(true);
View switchCamera = findViewById(R.id.switch_camera);
switchCamera.setVisibility(View.VISIBLE);
switchCamera.setOnClickListener(this);
}
current = bfc;
}
@Override
public void onClick (View v) {
switch (v.getId()) {
case R.id.switch_camera:
FragmentManager fm = getSupportFragmentManager();
current = (current == bfc) ? ffc : bfc;
fm.beginTransaction().replace(R.id.camera_preview, current).commit();
break;
}
}