Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Error while scanning sometimes on android #137

Closed
tmfelwu opened this issue Jan 3, 2016 · 17 comments
Closed

Error while scanning sometimes on android #137

tmfelwu opened this issue Jan 3, 2016 · 17 comments

Comments

@tmfelwu
Copy link

tmfelwu commented Jan 3, 2016

On android, sometimes, when the code is scanned the scanner doesnt close and if u continue scanning after scan that the scanner closes with {text:"", cancelled: true}

@kbytesys
Copy link

kbytesys commented Jan 4, 2016

It happend also to me in my samsung s3 mini.

The first scan works fine, then the scanner scan the code twice and returns {text:"", cancelled: true}

@kbytesys
Copy link

kbytesys commented Jan 5, 2016

I made an interesting test:

$scope.scanBarcode = function() {
    alert("With this alert, the scan will work");

    $cordovaBarcodeScanner.scan().then(function(imageData) {
      alert(imageData.text);
      console.log("Barcode Format -> " + imageData.format);
      console.log("Cancelled -> " + imageData.cancelled);
    }, function(error) {
      alert(error);
      console.log("An error happened -> " + error);
    });
  };

It's a bit weird, but the scan works. This doesn't solve the issue, but can help to find what's wrong.

@tmfelwu
Copy link
Author

tmfelwu commented Jan 6, 2016

Yeah i think the js code is fine, something probably wrong with the java code here I think this test resultCode == Activity.RESULT_OK is failing and this.callbackContext.error("Unexpected error"); is being called. I have no idea where to go from here. I would be happy if it atleast gives the correct result after second scan. Idk java @kbytesys can u look into it.

@kbytesys
Copy link

kbytesys commented Jan 6, 2016

That java code doesn't explain why the barcode reader tries to scan twice.

I think there are some bug in the activation of the cordova plugin or in the zxing library installed in some phones, but I'm unable to debug this issue atm :(

Maybe some official dev could try to recreate the bug or just release the plugin with some extra debug log info 😸

@tmfelwu
Copy link
Author

tmfelwu commented Jan 7, 2016

given the amount of activity here that will be a long time

@kbytesys
Copy link

kbytesys commented Jan 7, 2016

Maybe this issue could be related

#124

@kbytesys
Copy link

kbytesys commented Jan 9, 2016

@sparshy please, you can try if my fork submitted in the pr solves your problem?

https://github.com/kbytesys/phonegap-plugin-barcodescanner/tree/android-zxing-integration

@tmfelwu
Copy link
Author

tmfelwu commented Jan 14, 2016

@kbytesys No still the same error, is it working for you?

@kbytesys
Copy link

@sparshy yep

did you removed the old plugin and added mine with

cordova plugin add https://github.com/kbytesys/phonegap-plugin-barcodescanner.git#android-zxing-integration

?

@fonini
Copy link

fonini commented Jan 21, 2016

Wrapping the plugin call with a setTimeout also works.

@tmfelwu
Copy link
Author

tmfelwu commented Jan 21, 2016

@fonini can you elaborate

@kbytesys yes i did install ur plugin

@fonini
Copy link

fonini commented Jan 22, 2016

@sparshy I've used the $timeout from Ionic/Angular

$timeout(function(){
    cordova.plugins.barcodeScanner.scan(
      function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
      }, 
      function (error) {
          alert("Scanning failed: " + error);
      }
   );
});

But I guess you can use a simple setTimeout instead the $timeout.

@koga73
Copy link

koga73 commented Feb 5, 2016

@fonini Wrapping in a $timeout worked for me. Do you have any idea what the issue is and why this would fix it?

@fonini
Copy link

fonini commented Feb 5, 2016

@koga73 Unfortunately, I have no idea why.

@koga73
Copy link

koga73 commented Feb 5, 2016

I've noticed when it is going to "fail" the barcode scanner almost appears to open twice. Any scanning after and it fails. The timeout works most of the time but I still saw it fail once or twice. I added a 100ms delay to the timeout and it seems to be better now.

@koga73
Copy link

koga73 commented Feb 8, 2016

Update: This is the same as issue #38
Change "ng-click" to "on-touch". This also explains why the timeout was somewhat effective.

@lock
Copy link

lock bot commented Jun 8, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

5 participants