1

我想使用以下方法在 Android 手机上打开一个新的 Camera 实例:

camera = Camera.open();

在我这样做之前,我会检查是否有带有 PacketManager 的摄像头。我还在清单中添加了permission.CAMERAand 功能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"/>
    ...
4

0 回答 0