dlazaro66 / QRCodeReaderView

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
1.9k stars 491 forks source link

java.lang.RuntimeException: Fail to connect to camera service #109

Closed CrawlerChaos closed 7 years ago

CrawlerChaos commented 7 years ago

java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.(Camera.java:575) at android.hardware.Camera.open(Camera.java:410) at com.google.zxing.client.android.camera.open.OpenCameraInterface.open(OpenCameraInterface.java:76) at com.google.zxing.client.android.camera.CameraManager.openDriver(CameraManager.java:96) at com.dlazaro66.qrcodereaderview.QRCodeReaderView.surfaceCreated(QRCodeReaderView.java:183) at android.view.SurfaceView.updateWindow(SurfaceView.java:597) at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:179) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2098) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1150) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6061) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860) at android.view.Choreographer.doCallbacks(Choreographer.java:672) at android.view.Choreographer.doFrame(Choreographer.java:608) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5458) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

Hi dlazaro66,how can i slove this problem,thanks. is this issue caused by the Camera Permission on Android M+?

nabilsouk commented 7 years ago

@CrawlerChaos yes it is. You better check for the permission before initializing the view.

@dlazaro66 thanks for the wrapper man, but any error in the library should be handled in a way or another. Currently having your view in the layout can cause an exception immediately.

dlazaro66 commented 7 years ago

@CrawlerChaos yes, that's the problem.

@nabilsouk IMO, You should provide a way to init the decoding only if the user accepted the use of the camera. You can find in the Sample a very simple way to do it. I can add a double check in the library itself, but imho, the library user should provide it.

I'll close the issue since this is not related to it and you already pointed the user what was the problem. If you want to keep talking about it, you can open another issue in order to discuss it. Thanks :)