相关文章推荐
讲道义的高山  ·  pd.set_option("display ...·  3 月前    · 
腼腆的蚂蚁  ·  详情 - 项目公示 - ...·  1 年前    · 
骑白马的皮带  ·  React Typescipt ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am facing this issue, it occurs rarely but once it occurs user cannot go forward as there is no workaround that I am able to do.

While the user clicks on capture the camera is working in the background, but still i am getting camera is closed error.

Device info :
Brand : Nokia
Android version : 10
Model : Nokia 6.1 Plus

This is the code I am using to capture image

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 is : **Camera is closed.**
                What do you mean by "the camera is working in the background"? Is it used by the same app or a different one?
– Husayn Hakeem
                Aug 29, 2021 at 23:51
                Hey @HusaynHakeem by "background" I mean that the camera frames are active while I get this error. Actually I have a transparent progress dialog window which shows on top of the camera so I can see that the camera frames are active but still I get this error
– Akash Sarkar
                Sep 6, 2021 at 10:32

In CameraX the ImageCapture use case is stable so this bug shouldn't occur even rarely, so in the cases of the error, the camera is closed due to either a problem in your logic of when exactly you are calling imageCapture.takePicture(), or for example when you take a picture and the app pauses before the image is saved, it will throw the error you mentioned.

for example when you take a picture and the app pauses before the image is saved, great, this inspires me! UPVOTE! – atline Sep 1, 2021 at 2:32 Hey, Actually the app is in production and every one is using the camera without any issue, but just this one user is having the issue. The logic is proper and user is not putting the app in background while doing this. Also the camera frames are active while I get this error. – Akash Sarkar Sep 6, 2021 at 10:35 If this issue occurs only for one user then maybe it's a bug for the certain device, so you should really ask the CameraX developers about it at this group. Provide the device info when you do ask them so they will be able to recreate the error and then fix it – Raz Leshem Sep 6, 2021 at 19:19

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.