在我的Android应用中,我有一个倒数计时器。当计时器达到0时,相机应打开并拍摄三张照片,即拍摄并关闭。定时器达到0后,相机拍摄3张并将其保存到图库,但屏幕上看不到相机,即我没有看到相机出现,但不知何故正确拍摄照片。
在onCreate中,我用这个初始化相机:
private void openCamera() {
if (!getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
.show();
} else {
cameraId = findFrontFacingCamera();
if (cameraId < 0) {
Toast.makeText(this, "No front facing camera found.",
Toast.LENGTH_LONG).show();
} else {
camera = Camera.open(cameraId);
}
}
}
/*
* This function find the front facting camera in the device.
*/
private int findFrontFacingCamera() {
int cameraId = -1;
// Search for the front facing camera
int numberOfCameras = 0;
numberOfCameras = Camera.getNumberOfCameras();
Log.d(DEBUG_TAG, "Camera found" + numberOfCameras);
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
Log.d(DEBUG_TAG, "Camera found");
cameraId = i;
break;
}
}
return cameraId;
}
然后一旦计时器达到0,我就这样做了:
Onfinish()
{
camera.startPreview();
safeToTakePicture = true;
camera.takePicture(null, null, new PhotoHandler(getApplicationContext()));
safeToTakePicture = false;
}
有人可以帮忙吗?虽然相机正在拍照,但它并没有在屏幕上显示出来。