简体   繁体   中英

cordova plugin barcode scanner doesn't open the scan

I have a problem with the barcode scanner plugin (I'm not a genius and I don't know well how to programm a web-app.).
I use phonegap and cordova and I've tried to do a web-app that scan a barcode after a click on a link.
I've installed the plugin, before with this command line:

cordova plugin add cordova-plugin-barcodescanner

and I write this js code:

function scan(){
 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);
  }
 );
}

in html:

<a href="javascript:void(0);" onclick="scan()">Scan</a>

But when I click on the link, It doesn't happen anything.
If I put an alert after: function scan(){, it show if I put an alert after: cordova.plugins.barcodeScanner.scan(, doesn't do anything.
So, I tried to uninstall the plugin and install it with this command line:

cordova plugin add com.phonegap.plugins.barcodescanner

With the same js and html code, but it doesn't work yet.
So, I uninstall the plugin and I try to install it with:

cordova plugin add https://github.com/wildabeast/BarcodeScanner.git

But anything yet. I search a lot and I try a lot of solutions!
I use cordova 5.0.0 and I try the plugin on android 4.4 and IOS.
I also installed the plugin camera. So, please, help me! Where is the error?
I followed all the solutions that I've find on the web and on stackoverflow.
The code always crashes after:

cordova.plugins.barcodeScanner.scan(

Can anyone help me, please? Thank you so much.

首先,您可以使用firebug在firefox中检查您的代码,看看它是否给出了可以使您这样做的错误,或者您可以尝试使用其他intelXDK库

document.addEventListener("intel.xdk.device.barcode.scan",function(evt){});

You have to add the feature to the config.xml in case of Android as below:

<feature name="BarcodeScanner">
    <param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM