3

I'm new on Phonegap and JS... and I tried it with a barcode scanner... I installed the phonegap and everything with this tutorial http://teusink.blogspot.com/2013/07/guide-phonegap-3-android-windows.html

I installed the BarcodeScanner from CMD and exported the project as android platform... Add it to Eclipse ... followed all the tutorials how to do it, added all permissions and stuff..

when i try the app on ma samsung tab2 ... the app comes up but when i click the "scan" link i get the error uncaught module cordova/plugin/BarcodeScanner not found in the logcat.

this is the call <a href="#" class="btn large" onclick="scaning();">Scan</a

i have this in the index html head

<script src="phonegap.js"></script> 
<script src="barcodescanner.js"></script>

this is the scaning function function scaning(){

var scanner = cordova.require("cordova/plugin/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 is in the config.xml

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

I think I checked the whole Google for the answer ... but till now nothing worked... and still for the phonegap 3.0+ version there is almost none documentation for the barcode scanner ... at least for a beginner ...

if you can help me guys .... couse I'm totally lost :S

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
LitBe
  • 183
  • 2
  • 11

4 Answers4

7

Although I've never used older versions as I'm quite new into Phonegap/Cordova, Version 3.1 seems to use a slightly different approach for accessing plugins. Following worked for me with Cordova 3.1 and BarcodeScanner.

Install plugin with

plugman install --platform android --project=DIR-TO-CORDOVA-PROJECT --plugin=https://github.com/wildabeast/BarcodeScanner

You don't have to reference barcodescanner.js by your own, cordova takes care of the includes - the example code from https://github.com/wildabeast/BarcodeDemo worked except I had to change the plugin path from

var scanner = cordova.require("cordova/plugin/BarcodeScanner");

to

var scanner = cordova.require("com.phonegap.plugins.barcodescanner.BarcodeScanner");
maetthu
  • 641
  • 8
  • 10
2

This one worked for me:

var scanner = cordova.plugins.barcodeScanner;
Pang
  • 9,564
  • 146
  • 81
  • 122
LitBe
  • 183
  • 2
  • 11
2

edit the file: js/index.js

find the code: var scanner = cordova.require("cordova/plugin/BarcodeScanner");

replace "cordova/plugin/BarcodeScanner" to "com.phonegap.plugins.barcodescanner.BarcodeScanner"

Doctor.Who.
  • 607
  • 1
  • 7
  • 15
0

Had the same problem , got fixed by installing it via plugman like this

plugman install --platform android --project=DIR-TO-CORDOVA-PROJECT --plugin=https://github.com/wildabeast/BarcodeScanner

where DIR-TO-CORDOVA-PROJECT is E:/ProjectName/platform/android

If I didn't add the /platform/android it gave an error

and then put this in the scanning() 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);
                  }
               );
Lau
  • 282
  • 3
  • 11