Skip to content

Bug : Fail to connect to camera service - With explanation, steps to reproduce and possible fix #55

Description

@LainCoubrt

Hi.
I had the RuntimeException: Fail to connect to camera service.
Log:

java.lang.RuntimeException: Fail to connect to camera service
    at android.hardware.Camera.<init>(Camera.java:545)
    at android.hardware.Camera.open(Camera.java:385)
    at com.google.android.gms.vision.CameraSource.zzbjo(Unknown Source)
    at com.google.android.gms.vision.CameraSource.start(Unknown Source)
    at github.nisrulz.qreader.QREader.startCameraView(QREader.java:221)
    at github.nisrulz.qreader.QREader.access$400(QREader.java:40)
    at github.nisrulz.qreader.QREader$1.surfaceCreated(QREader.java:68)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:607)
    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:246)
    at android.view.View.dispatchWindowVisibilityChanged(View.java:9322)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1285)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1468)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
    at android.view.Choreographer.doCallbacks(Choreographer.java:590)
    at android.view.Choreographer.doFrame(Choreographer.java:560)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5951)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)

This is due to the camera being used from another app and not be released when the app goes to background.

I can give the steps to reproduce this issue if you need.

This exception is thrown in QREader.java in line 221, and is not caught by the IOException beacause it's a RunTimeException and we can't catch it because it's thrown in a background thread when surface is created.

So to just fix the crash just change the IOException for just an Exception.

Although this resolves the issue i think it's important to send feedback to the user and just catch the exception and print the error we cant do that. I think it would be useful some sort of listener so we could know the errors when the camera fails.

Please if you could change this as soon as possible would be very helpful. And if you need any help just ask.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions