我正在尝试从我的应用中打开相机。我的相机活动代码如下所示 -
Button click = (Button) activity.findViewById(R.id.captureclick);
if (!getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
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." + cameraId,
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "cameraId : "+cameraId,
Toast.LENGTH_LONG).show();
camera = Camera.open(cameraId);
}
}
click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
camera.takePicture(null, null,
new PhotoHandler(CameraActivity.this));
}
});
@Override
protected void onPause() {
super.onPause();
if (camera != null) {
camera.release();
camera = null;
}
}
private int findFrontFacingCamera() {
int cameraId = -1;
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_FRONT){
}
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
cameraId = i;
break;
}
}
return cameraId;
}
现在我的PhotoHandler.class看起来如下 -
public class PhotoHandler implements PictureCallback {
private final Context context;
public PhotoHandler(Context context) {
this.context = context;
}
@Override
public void onPictureTaken( final byte[] data, Camera camera) {
camera.stopPreview();
camera.release();
camera = null;
// save data on storage
}
}
我遇到的问题是当我从我的设备上点击相机按钮然后打电话不会去Photohandler课程。我在日志中收到错误 -
I/CameraClient(128): Opening camera 0
I/NvOmxCamera(128): HAL_camera_device_open: open camera 0
E/(128): ioctl SetWhiteBalance failed: -1
E/NvOmxCameraSettingsParser(128): Param type 70 not supported
I/NvOmxCamera(128): HAL_camera_device_open: opened camera 0 (0x41fc07e0)
D/Camera 01(2958): Finish Opening Camera
I/ActivityManager(485): Displayed com.example.testlogin/.CameraActivity: +148ms
D/Camera 1(2958): Clicked on Camera
D/NvOsDebugPrintf(128): NvMMLiteBlockCreate : Block : BlockType = 1
D/NvOsDebugPrintf(128): NvMMLiteJPEGEncGetBufferRequirements : BufferSize 1843200
D/(128): Camera fd open as: 131
D/NvOsDebugPrintf(128): Image Physically rotated in DZ
D/NvOsDebugPrintf(128): NvMMExif_Orientation_0_Degrees= 1
E/NvOmxCamera(128): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoMode(NvxComponent*, NvOmxCameraUserStereoMode&): Error: invalid NVX mode 0.
E/NvOmxCamera(128): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoModeAndCaptureInfo(NvxComponent*, NvOmxCameraUserStereoMode&, NVX_STEREOCAPTUREINFO&): getCameraStereoMode failed with 0x00000000
D/NvOsDebugPrintf(128): NvMMLiteJPEGEncSetAttribute: Incorrect value 0 for stereo capture type
/NvOmxCameraSettings(128): OMX_ERRORTYPE android::programStereoInfo(OMX_HANDLETYPE, const NVX_STEREOCAPTUREINFO&, android::NvxWrappers*): pNvxWrappers->OMX_SetConfigIL failed with 0x80001005
我没有找到任何解决方案。请帮帮我。