我正在写一个相机应用程序,每当我调用camera.open()应用程序崩溃然后我收到此错误:
W/CameraBase? An error occurred while connecting to camera: 0
这是我打开相机的方式:
public void getCameraInstance(){
mCamera = null;
try
{
mCamera = Camera.open(); // attempt to get a Camera instance
}
catch (Exception e)
{
// Camera is not available (in use or does not exist)
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
如果您正在阅读本文,请注意这是原始相机API,不再适用最新版本的相机API(相机2).
从这一点开始,您应该使用camera2 api,因为它具有更强大的功能,并且还具有更好的图像处理流水线.
注意仅限于排除API 21(Lolipop),即不适用于Lolipop及以上.