wildabeast / BarcodeScanner

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

Can't get it working #316

Open rocifier opened 8 years ago

rocifier commented 8 years ago

Hi, I tried installing BarcodeScanner into a blank template phongap 5.3.9 project using the following command line while in my project directory:

phonegap plugin add phonegap-plugin-barcodescanner

This created various directories within the project and changed config.xml in the android folder. I then added this code to my index.js under the definition of app:

scanBarcode: function(){
   var scanner = cordova.plugins.barcodeScanner;
   scanner.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);
      }
   );
}

and this code in html:

<button class="app-button" onclick="app.scanBarcode();">Scan Barcode</button>

but when I host the app using PhoneGap Desktop and access it on my android device using the Phonegap Development App, nothing happens when I tap the button on my app. What am I doing wrong?

rocifier commented 8 years ago

I saw this in another issue, and tried it:

document.addEventListener("deviceready", function () { if (window.cordova) { alert('window.cordova is available'); } else { alert('window.cordova NOT available'); } }, false); document.addEventListener("deviceready", function () { if (window.cordova && window.cordova.plugins) { alert('window.cordova.plugins is available'); } else { alert('window.cordova.plugins NOT available'); } }, false);

On run as described above, I get: window.cordova is available window.cordova.plugins NOT available

ghost commented 8 years ago

I have the same issue, nothing happens when I click the button. I did check, and window.cordova.plugins is available.

cordova.plugins.barcodeScanner.scan is also available and is a function, so all is correct. I'm using the default example from this github project:

        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 it simply does nothing (apart from my own added alerts before / after )

Could this be some kind of permission error? Any ideas?...