android / android/camera-samples

Camera is closed exception on takePicture()

Open
#410 14 comments 1 reaction 0 assignees View on GitHub
more info
Dominant language
Kotlin
Stars
5.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Hi,
I am using camera2 in my app. Generally camera works fine for most of the users but for some users when they try capture image an exception is thrown with message "Camera is closed."
While this error occurs camera is actually actively working on UI, so not sure why this error is happening.

Code I am using to capture image is :
```
imageCapture.takePicture(outputFileOptions, ContextCompat.getMainExecutor(getContext()),
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) {

imagePath = FileProvider
.getUriForFile(getContext(), getContext().getPackageName() + ".provider", imageFile);
checkImageOrientation();
}

@Override
public void onError(ImageCaptureException error) {
// error.getMessage() --> Camera is closed.
}
});
```

Please let me know how to fix this.
Thank you!

Contributor guide

Open the contributing guide

Research direction

Start at the ImageCapture.takePicture call and its OnImageSavedCallback.onError handler, then investigate the camera lifecycle around the reported "Camera is closed" exception. Reproduce the failure for affected users and determine the conditions that close the camera while it remains active in the UI; done means the cause and a verified fix are identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.