使用前置摄像头拍摄照片

时间:2013-07-05 01:40:35

标签: android android-camera android-capture

我正在关注此链接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

1 个答案:

答案 0 :(得分:1)

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

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

查看this问题。