Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inflating the view before the camera permission is given and then starting the scanner after the permission is granted crashes #156

Open
Dima-369 opened this issue Mar 13, 2018 · 2 comments

Comments

@Dima-369
Copy link

The sample app avoids this by only inflating the layout when the camera permission is given.

We are migrating this library into our project and this would allow us to quickly port everything without rewriting all the view logic.


You can emulate this quickly by moving the line below from initQRCodeReaderView() to onCreate() while keeping the content variable as a class member variable:

View content = getLayoutInflater().inflate(R.layout.content_decoder, mainLayout, true);

The sample app will then crash (after quickly displaying a single camera frame) with:

java.lang.RuntimeException: An error occurred while executing doInBackground()                                                                              
   at android.os.AsyncTask$3.done(AsyncTask.java:309)                                                                              
   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)                                                                              
   at java.util.concurrent.FutureTask.setException(FutureTask.java:223)                                                                              
   at java.util.concurrent.FutureTask.run(FutureTask.java:242)                                                                              
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)                                                                              
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)                                                                              
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)                                                                              
   at java.lang.Thread.run(Thread.java:818)                                                                              
Caused by: java.lang.IllegalArgumentException: Both dimensions must be greater than 0                                                                              
   at com.google.zxing.common.BitMatrix.<init>(BitMatrix.java:50)                                                                              
   at com.google.zxing.common.GlobalHistogramBinarizer.getBlackMatrix(GlobalHistogramBinarizer.java:91)                                                                              
   at com.google.zxing.common.HybridBinarizer.getBlackMatrix(HybridBinarizer.java:86)                                                                              
   at com.google.zxing.BinaryBitmap.getBlackMatrix(BinaryBitmap.java:85)                                                                              
   at com.google.zxing.qrcode.QRCodeReader.decode(QRCodeReader.java:77)                                                                              
   at com.dlazaro66.qrcodereaderview.QRCodeReaderView$DecodeFrameTask.doInBackground(QRCodeReaderView.java:355)                                                                              
   at com.dlazaro66.qrcodereaderview.QRCodeReaderView$DecodeFrameTask.doInBackground(QRCodeReaderView.java:329)                                                                              
   at android.os.AsyncTask$2.call(AsyncTask.java:295)                                                                              
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                              
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)                                                                               
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)                                                                               
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)                                                                               
   at java.lang.Thread.run(Thread.java:818)
@vietmobilefolk
Copy link

@Gira-X : Could you try use ViewStub as placeholder for QRCodeReaderView, then only inflate when permission granted?

@Dima-369
Copy link
Author

Yes, that works indeed!

Here is the modified sample repo which uses a ViewStub: https://github.com/Gira-X/QRCodeReaderView


But in the end we decided to use a Google Vision API view because it scans a bit faster: https://github.com/wax911/Vision-Barcode-Scanner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants