我想使用以下方法在Android手机上打开一个新的Camera实例:
camera = Camera.open();
在我这样做之前,我会检查是否有带PacketManager的摄像头。我还在清单中添加了permission.CAMERA
和功能hardware.camera
。如果我尝试打开实例,我总会得到一个
01-05 13:47:48.720: E/Camera(6555): Error -2147483648
有谁能告诉我为什么会这样,以及我如何打开一个实例?
01-05 16:54:39.670: E/AndroidRuntime(9295): FATAL EXCEPTION: Thread-17341
01-05 16:54:39.670: E/AndroidRuntime(9295): java.lang.RuntimeException: Fail to connect to camera service
01-05 16:54:39.670: E/AndroidRuntime(9295): at android.hardware.Camera.native_setup(Native Method)
01-05 16:54:39.670: E/AndroidRuntime(9295): at android.hardware.Camera.<init>(Camera.java:302)
01-05 16:54:39.670: E/AndroidRuntime(9295): at android.hardware.Camera.open(Camera.java:279)
01-05 16:54:39.670: E/AndroidRuntime(9295): at com.arcticcoding.nxtphone.MainActivity$GetCameraInstance.getCameraInstance(MainActivity.java:73)
01-05 16:54:39.670: E/AndroidRuntime(9295): at com.arcticcoding.nxtphone.MainActivity$GetCameraInstance.run(MainActivity.java:84)
01-05 16:54:39.670: E/AndroidRuntime(9295): at java.lang.Thread.run(Thread.java:856)
这是我打开相机实例的方法
private Camera getCameraInstance() {
Camera camera = null;
try {
Log.d(TAG, "Opening camera instance");
camera = Camera.open();
} catch(Exception e) {
Log.d(TAG, "Error while opening camera");
e.printStackTrace();
}
return camera;
}
...
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
...