You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CameraView/docs/_docs/error-handling.md

49 lines
1.7 KiB

---
layout: page
title: "Error Handling"
Metering APIs (#580) * Add cameraPictureMetering and cameraPictureSnapshotMetering * Adapt Meter and metering package to picture use * Simplify Full2PictureRecorder, we'll use metering package instead * Add doMetering parameter * Implement cameraPictureMetering and cameraPictureSnapshotMetering in engine * Add options in demo app * Add better logs * Add Snapshot2PictureRecorder * Capture the correct frame based on timestamp * Lock AE and AWB. Account for captureBuilder changes * Fix runtime flash changes bug * Small changes * Flash support for metered snapshots * Remove AE and AWB locks * Lock AE/AWB/AF inside the snapshot recorder * Small changes * Fix AutoExposure metering * Create Locker and locking.* parameters * Implement Locker in Camera2Engine * Implement reset delay in Camera2Engine instead of Meter * Simplify Snapshot2PictureRecorder * Fix success value * Unlock inside Camera2Engine * Do not lock for normal gestures * Simplify logic * Improve locking/AutoFocus * Fix TORCH bug * Small changes to locking and metering * Remove AF and AWB for testing * Create action package * Create OneShotAction * Create LogAction * Revisit Full2VideoRecorder using actions * Revisit Full2PictureRecorder using actions * Enable missing functionality in Snapshot2PictureRecorder * Move Snapshot2PictureRecorder using actions, rewrite lock package * Add TimeoutAction * Add comments to the action package * Add meter package * Remove old metering package * Fix various bugs * Add action.abort() * Abort old MeterAction when running new ones * Fix various bugs * Add doc empty page * Add documentation * Fix tests
5 years ago
order: 14
6 years ago
disqus: 1
---
Errors are posted to the registered `CameraListener`s callback:
```java
@Override
public void onCameraError(CameraException error) {
// Got error!
};
```
You are supposed to inspect the `CameraException` object as it contains useful information about
what happened and what should be done, if anything. All things that fail can end up throwing this
exception, which includes temporary actions like taking a picture, or functional actions like
starting the camera preview.
### Unrecoverable errors
You can exclude unrecoverable errors using `CameraException.isUnrecoverable()`.
If this function returns true, at this point the camera has been released and it is likely showing
a black preview. The operation can't go on.
You can try to call `camera.start()` again, but that's not guaranteed to work. For example, the
camera sensor might be in use by another application, so there's nothing we could do.
### Other errors
For more fine grained control over what happened, inspect the reason using `CameraException.getReason()`.
This will return one of the `CameraException.REASON_` constants:
|Constant|Description|Unrecoverable|
|--------|-----------|-------------|
|`REASON_UNKNOWN`|Unknown error. No other info available.|No|
|`REASON_FAILED_TO_CONNECT`|Failed to connect to the camera service.|Yes|
|`REASON_FAILED_TO_START_PREVIEW`|Failed to start the camera preview.|Yes|
|`REASON_DISCONNECTED`|Camera was forced to disconnect by the system.|Yes|
|`REASON_PICTURE_FAILED`|Could not take a picture or picture snapshot.|No|
|`REASON_VIDEO_FAILED`|Could not take a video or video snapshot.|No|
|`REASON_NO_CAMERA`|Could not find a camera for this `Facing` value. You can try another.|No|