0

我正在关注此链接http://www.vogella.com/articles/AndroidCamera/article.html#tutorial_cameraapi

只有我改变了cameraId = findFrontFacingCamera(); 行至cameraId = findBackFacingCamera();

并编写如下方法:

  private int findBackFacingCamera() {
    int cameraId = -1;
    // Search for the back facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
      CameraInfo info = new CameraInfo();
      Camera.getCameraInfo(i, info);
      if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
        Log.d(DEBUG_TAG, "back Camera found");
        cameraId = i;
        break;
      }
    }
    return cameraId;
  }

我修改了这条线camera.takePicture(null, null, new PhotoHandler(getApplicationContext()));

try {
        camera.takePicture(null, null, new PhotoHandler(getApplicationContext()));
    } catch (Throwable e) {
        Log.d("error",""+e);
    }

我什么都没改变

我在 Galaxy Fit 上检查的设备

给出错误

07-05 07:09:06.159: D/error(26994): java.lang.NullPointerException
4

1 回答 1

1

您必须将此权限用于前置摄像头

<uses-feature android:name="android.hardware.camera.front" android:required="false" />

看看这个问题。

于 2013-07-05T04:22:31.120 回答