microg/GmsCore · error · IOException
Could not find requested camera.
Error message
Could not find requested camera.
What it means
CameraSource.getFacingCameraId() iterates all hardware cameras via Camera.getCameraInfo() looking for one matching the requested facing (front/back) and throws IOException when no camera with that facing exists. This surfaces at camera-open time when the device simply lacks the requested camera.
Source
Thrown at play-services-vision-common/src/main/java/com/google/android/gms/vision/CameraSource.java:354
});
camera.addCallbackBuffer(new byte[(int) Math.ceil((double) ((long) (previewSize.getHeight() * previewSize.getWidth() * ImageFormat.getBitsPerPixel(parameters.getPreviewFormat()))) / 8.0D) + 1]);
return camera;
} catch (Exception e) {
camera.release();
throw e;
}
}
private int getFacingCameraId() throws IOException {
Camera.CameraInfo info = new Camera.CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
Camera.getCameraInfo(i, info);
if (info.facing == facing) {
return i;
}
}
throw new IOException("Could not find requested camera.");
}
private int[] pickFpsRange(Camera camera) throws IOException {
int requestsFpms = (int) (requestedFps * 1000.0F);
int[] selectedFpsRange = null;
int selectedPreviewFpsOffset = Integer.MAX_VALUE;
for (int[] previewFpsRange : camera.getParameters().getSupportedPreviewFpsRange()) {
int minOffset = requestsFpms - previewFpsRange[0];
int maxOffset = requestsFpms - previewFpsRange[1];
int previewFpsOffset;
if ((previewFpsOffset = Math.abs(minOffset) + Math.abs(maxOffset)) < selectedPreviewFpsOffset) {
selectedFpsRange = previewFpsRange;
selectedPreviewFpsOffset = previewFpsOffset;
}
}
if (selectedFpsRange == null) throw new IOException("Could not find suitable preview frames per second range.");
return selectedFpsRange;View on GitHub (pinned to 157c9d86ac)
Solutions
- Detect available facings first by iterating Camera.getNumberOfCameras()/getCameraInfo and pick a supported one
- Default to CAMERA_FACING_BACK if front is unavailable (or vice versa)
- Show a user-facing message when the device lacks the requested camera
- Guard start() in try/catch for IOException and fall back to the other facing
Example fix
// before
CameraSource source = new CameraSource.Builder(context, detector)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.build();
source.start(); // IOException on devices without a front camera
// after
int facing = hasCamera(CameraInfo.CAMERA_FACING_FRONT)
? CameraSource.CAMERA_FACING_FRONT : CameraSource.CAMERA_FACING_BACK;
try {
CameraSource source = new CameraSource.Builder(context, detector)
.setFacing(facing).build();
source.start();
} catch (IOException e) {
// no suitable camera on this device
} Defensive patterns
Strategy: try-catch
Validate before calling
boolean hasFacing(int facing) {
Camera.CameraInfo info = new Camera.CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
Camera.getCameraInfo(i, info);
if (info.facing == facing) return true;
}
return false;
} Type guard
null
Try / catch
try {
cameraSource.start();
} catch (IOException e) {
// no camera with the requested facing: fall back or inform the user
} Prevention
- Enumerate available cameras and choose a supported facing dynamically
- Default to back camera when front is unavailable
- Never hardcode camera facing for arbitrary devices
When it happens
Trigger: Requesting CameraSource with CameraInfo.CAMERA_FACING_FRONT (or back) on a device that has no front (or back) camera; calling start() on devices with a single rear camera when front was requested.
Common situations: Desktop/emulator or IoT devices without the requested camera; enterprise tablets with rear-only cameras; hardcoded FRONT camera assumption in code running on rear-only hardware.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not find suitable preview frames per second range.
- No context supplied.
- No detector supplied.
- Could not read from parcel file descriptor
- CameraUpdateFactory is not initialized
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/56f1478a457b53f5.
Report an issue: GitHub.