下面列出了android.hardware.camera2.CameraAccessException#CAMERA_ERROR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressLint("SwitchIntDef")
@Override
public String getErrorString(CameraAccessException e) {
String errorMessage;
switch (e.getReason()) {
case CameraAccessException.CAMERA_DISABLED:
errorMessage = getString(R.string.camera_disabled);
break;
case CameraAccessException.CAMERA_DISCONNECTED:
errorMessage = getString(R.string.camera_disconnected);
break;
case CameraAccessException.CAMERA_ERROR:
errorMessage = getString(R.string.camera_error);
break;
default:
errorMessage = getString(R.string.camera_unknown, e.getReason());
break;
}
return errorMessage;
}
private void checkIfCameraClosedOrInError() throws CameraAccessException {
if (mRemoteDevice == null) {
throw new IllegalStateException("CameraDevice was already closed");
}
if (mInError) {
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR,
"The camera device has encountered a serious error");
}
}
/** Fetches the camera characteristics for the current camera. */
private boolean initCameraCharacteristics() {
CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
try {
// Extract characteristics for the current camera.
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
activeArraySize = characteristics.get(SENSOR_INFO_ACTIVE_ARRAY_SIZE);
maxDigitalZoom = characteristics.get(SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
// Require a stream configuration map. Don't know why there wouldn't be one.
StreamConfigurationMap map = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR);
}
int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
boolean lensFacingFront = (facing == CameraCharacteristics.LENS_FACING_FRONT);
int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
outputOrientation = Orientation.getOutputOrientation(
lensFacingFront, displayRotationCode, sensorOrientation);
return true;
} catch (CameraAccessException | NullPointerException e) {
// NPE's can be thrown when unboxing some of the characteristics. This should never happen
// on Pixel{1,2}.
Log.w(TAG, "Failed to inspect camera characteristics", e);
}
return false;
}