wildabeast / BarcodeScanner

Official repository now at [phonegap/phonegap-plugin-barcodescanner](http://github.com/phonegap/phonegap-plugin-barcodescanner).
968 stars 743 forks source link

Callback receives data from previous scan on Android #107

Open hkrauss2 opened 10 years ago

hkrauss2 commented 10 years ago

UPDATE 4/22: This can be closed or deleted. It is not related to the BarcodeScanner, all plugin callbacks are showing the same behavior on the DROID ULTRA.

Thanks for the time you've spent on the plugin.

I have downloaded the BarcodeDemo files, changed the id of the widget in config.xml but kept the rest unchanged. I zipped and uploaded to PhoneGap Build (app id=881663).

The app installed fine on my Droid Ultra however I encounter the following behavior when I run it. The first attempt to scan a barcode the scanner window opens and it successfully tells me whether it scanned a URL or Plain Text but the JS callback is not called. The second attempt opens the scanner window, identifies the content as URL or plain text but sends the previous scan data to the callback. I've created three plain text QRCodes ("QRCode One", "QRCode Two", "QRCode Three") for testing (attached bellow).

If I scan QRCode One first after launch the callback doesn't get called. Then scanning QRCode Two returns the text "QRCode One" and so forth. Canceling a scan will still return data from the previous scan. Images and hardware info below. Any help is greatly appreciated.

UPDATE: A different Android device (DROIDX with Android 2.3.4) worked correctly. Seems to be related to the ULTRA or Android Version 4.4

UPDATE 4/21: This does not seem to be related specifically to the BarcodeScanner plugin. It looks to be related to callbacks with any plugin. I am having a similar issue with the File plugin.

one two three

Phone information: Hardware information RAM size: 2GB ROM size 16GB Display 1280x720 HD

System Version: 19.5.3.obake_verizon.Verizon.en.US MOdel number: DROID ULTRA System information: Motorola X8 Mobile Computing System Android version: 4.4 Baseband version: MSM8960PRO_BP_2323.026.100.00R

mstn commented 10 years ago

Same problem on Android 4.3 Huawei. @hkrauss2 have you found a workaround? Thanks.

hkrauss2 commented 10 years ago

Building locally instead of using PhoneGap Build solved it for me.

Eccenux commented 10 years ago

Strange... Works fine in my app. Which PG version did you use when compiling? Maybe the demo app has some old version hard coded?

Anyway you can test on my app - PP-tracker. The app folder contains the application, the release folder contains the apk. The app is in Polish, but just use the "Czytaj kod" button for testing (first on the left).

mstn commented 10 years ago

I built it locally. Cordova version: 3.4.1-0.1.0 @Eccenux thanks, I'll have a look at your code.

mstn commented 10 years ago

I had a better look at this weird behavior. The first callback is called the second time I invoke function scan and before the second callback should be called. I do not know, but maybe this could be a hint.

mstn commented 10 years ago

Somebody has (had?) the same/similar issue with another plugin in a more traditional setting http://stackoverflow.com/questions/19809164/navigator-camera-getpicture-callback-doesnt-execute-until-2nd-call

Unfortunately, the suggested workaround does not work for me.

The last link might suggest that it could be a cordova issue not related to a particular plugin. Any thought?

mstn commented 10 years ago

AdamBrodzinski suggested another workaround in this thread https://github.com/zeroasterisk/MeteorRider/issues/16

if (device.platform === 'Android') {
  setInterval(function () {
     cordova.exec(null, null, '', '', [])
  }, 200);
}

It works for me.

23pointsNorth commented 10 years ago

At what stage do you call the above mentioned code? Before adding an eventListener that would otherwise call the scan function?

rajatrocks commented 9 years ago

I put that code in right before my call to cordova.plugins.barcodeScanner.scan and it fixed the problem.

kinrepit commented 8 years ago

Experiencing the same callback not firinig issue with cordova-camera-plugin, unfortunately work-around suggested by @AdamBrodzinski did not work for me. My post at http://stackoverflow.com/questions/37808733/cordova-navigator-camera-getpicture-not-working-in-android