无法连接相机服务
我在堆栈上看到了很多问题,但没有人告诉我是否会发生无法连接到相机服务,以及如何摆脱此 RuntimeException
。
我有一个相机应用程序工作正常,我已经注意释放资源,但如果用户以某种方式安装了其他应用程序而无法正确释放资源,我的应用程序将面临 RuntimeException: 无法连接到相机服务
因此崩溃了,希望避免这种情况。
如果我单击原始相机应用程序,它会向我显示一个 AlertDialog
Camera error: Cannot connect to camera.
这就是我想要处理的问题。我正在尝试使用此代码来处理它,但尚未成功。
try {
camera = Camera.open();
camera.setDisplayOrientation(90);
} catch (RuntimeException e) {
// TODO: handle exception
Log.d("Inside RunTime exception", e+"//");
camera.setErrorCallback(errorCallback);
reConnectCameraVideo();
} catch(Exception e) {
finish();
}
但相机对象在 camera.setErrorCallback
上返回 null,因为它无法打开。
I had seen many questions on stack but no one is telling if a Fail to connect to camera service will occur, how to get rid of this RuntimeException
.
I have an camera application its working fine, I already take care to release the resources but if somehow user install the other application which not releasing the resources properly, my application facing RuntimeException: Fail to connect to camera Service
and hence got crashed, want to avoid this situation.
If i click on original camera application it shows me a AlertDialog
Camera error: Cannot connect to camera.
That's what i exactly want to handle this. I am trying this code to handle it but cant succeed yet.
try {
camera = Camera.open();
camera.setDisplayOrientation(90);
} catch (RuntimeException e) {
// TODO: handle exception
Log.d("Inside RunTime exception", e+"//");
camera.setErrorCallback(errorCallback);
reConnectCameraVideo();
} catch(Exception e) {
finish();
}
but camera object returning null on camera.setErrorCallback
because it wont open.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setErrorCallback()
不能用于Camera
无法打开的情况。您似乎仍在尝试继续使用相机
- AFAIK,如果其他应用程序泄漏了相机
,则除非用户重新启动手机,否则这是不可能的。只需显示您自己的消息即可达到此目的。另外:
使用错误日志记录服务,如 ACRA、Flurry、BugSense 等。
切勿因某个原因而盲目地完成某项活动。异常,如最后一个
catch
块中所示。始终做一些事情让用户和/或您(通过错误日志服务)了解异常setErrorCallback()
cannot be used for the case where theCamera
will not open. You appear to be trying to still use theCamera
-- AFAIK this is impossible until the user reboots their phone if some other app leaked theCamera
. Simply display your own message to that effect.Also:
Use an error logging service, like ACRA, Flurry, BugSense, etc.
Never blindly finish an activity due to an exception, as in your last
catch
block. Always do something to let the user and/or you (via the error logging service) know about the exception