所以我正在使用 camera2 api,当我打开相机时:
private void StartUpCam()
{
CameraManager CM = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
if(camId.compareTo("")!=0)
{
//Log.e("camera", "started");
try{
Log.e("Start up Cam and camId:", camId);
CM.openCamera(camId, CDcallback, null);
}
catch(CameraAccessException e)
{
Log.e("come with me", "if you want to live");
e.printStackTrace();
}
}
}
正如你所看到的,我确保打开相机所需的参数全部检查出来并且它们确实如此。无论如何,当回调被击中时:
private CameraDevice CD;
private CameraDevice.StateCallback CDcallback
= new CameraDevice.StateCallback() {
@Override
public void onOpened(CameraDevice camera) {
//Log.e("onOpened", "here");
CD = camera;
if(CD == null)
Log.e("onOpened", "CD is null");
createCamPreviewSession();
}
@Override
public void onError(CameraDevice camera, int error) {
camera.close();
CD = null;
}
@Override
public void onDisconnected(CameraDevice camera) {
camera.close();
CD = null;
}
};
onOpened 方法中的相机设备始终为空。我不知道为什么会这样。有任何想法吗?