BarcodeScanner icon indicating copy to clipboard operation
BarcodeScanner copied to clipboard

Callback receives data from previous scan on Android

Open hkrauss2 opened this issue 11 years ago • 10 comments

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

hkrauss2 avatar Apr 20 '14 23:04 hkrauss2

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

mstn avatar Jul 16 '14 12:07 mstn

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

hkrauss2 avatar Jul 16 '14 23:07 hkrauss2

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).

Eccenux avatar Jul 16 '14 23:07 Eccenux

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

mstn avatar Jul 17 '14 07:07 mstn

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 avatar Jul 18 '14 10:07 mstn

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 avatar Jul 18 '14 18:07 mstn

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.

mstn avatar Jul 21 '14 09:07 mstn

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

23pointsNorth avatar Aug 04 '14 15:08 23pointsNorth

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

rajatrocks avatar Oct 02 '14 18:10 rajatrocks

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

kinrepit avatar Jun 26 '16 16:06 kinrepit