Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phonegap 3.1 BarcodeScanner uncaught module cordova/plugin/BarcodeScanner not found

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

like image 336
LitBe Avatar asked Jan 26 '26 01:01

LitBe


2 Answers

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");
like image 148
maetthu Avatar answered Jan 27 '26 16:01

maetthu


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"

like image 35
Doctor.Who. Avatar answered Jan 27 '26 14:01

Doctor.Who.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!