我正在将相机用于条形码扫描仪应用程序,并且在某些设备(LG G Flex、华硕 Nexus 7)上得到:Android 运行时异常 - 无法连接相机服务。这是下面的清单文件的片段:
`uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
uses-permission android:name="android.permission.CAMERA"
....`
我在暂停、停止和销毁时释放相机。
/**
* Restarts the camera.
*/
@Override
protected void onResume() {
super.onResume();
try {
startCameraSource();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Stops the camera.
*/
@Override
protected void onPause() {
super.onPause();
if (mPreview != null) {
mPreview.stop();
}
}
/**
* Releases the resources associated with the camera source, the associated detectors, and the
* rest of the processing pipeline.
*/
@Override
protected void onDestroy() {
super.onDestroy();
if (mPreview != null) {
mPreview.release();
}
}
仍然超出运行时异常,并且我没有以上两个设备,因此我可以重现。有没有解决这个问题的办法?