Repository navigation
fix(scanner): fall back to any camera when there is no back camera - #1752
Merged
Merged
Conversation
The scanner required LENS_FACING_BACK. An Infinix X688B exposes one camera
to CameraX and reports it as front facing, so every bind threw
IllegalArgumentException("No available camera can be found"), was retried
three times a second apart, and left a blank preview (Bugsnag
6aca4823396a2e952015e21d, 9 events on 2026.10.2).
Prefer the back camera and otherwise bind the first camera the device
exposes. Stop retrying IllegalArgumentException, which doesn't change
between attempts. A device with no camera now fails with
NoCamerasAvailableException, which shows the unavailable state and is no
longer reported as an error.
When the device has no back camera, CodeScanner reports the front-camera fallback and the scan screen shows a floating toast, once per scanner: "No back camera found. Using your front camera."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The scanner required
LENS_FACING_BACK. An Infinix X688B exposes a single camera to CameraX and reports it as front facing, so every bind threwIllegalArgumentException: No available camera can be found.bindWithRetrytried three times, a second apart, and the user got a blank preview. Each return to the screen repeated it: 9 events on 2026.10.2 (Bugsnag6aca4823396a2e952015e21d).CodeScanner.kt: choose the camera at bind time. Use the back camera when there is one, otherwise the first camera the device exposes. A code held up to a front camera still scans.bindWithRetry: don't retryIllegalArgumentException. CameraX throws it when no camera matches or the use cases can't be combined, and neither changes between attempts.NoCamerasAvailableException, soScanner.ktshows the unavailable state. That case is no longer sent toErrorUtils.handleError, since it describes the device rather than a bug.The front-camera preview is mirrored. Analysis runs on the raw frames, but Kik code decoding on a front camera hasn't been tried.
ScannerCameraSelectionTestcovers the camera choice and the retry behaviour.