admin管理员组文章数量:1320815
Been trying this for a few hours now and have made a little progress but not in the right direction.
I have successfully setup an Android Cordova project which loads onto a phone and runs fine. I just cannot get the barcode scanner plugin to work in Cordova 3.1. I believe it has installed correctly but it does not appear in the config.xml, it does however appear in the cordova_plugins.js file etc.
I have this in my index.js
function clickScan() {
var scanner = cordova.require(".phonegap.plugins.barcodescanner.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);
}
);
}
Now when I press the scan button it seems to run this code but jumps straight to the success function and just displays the alert box with blank results.
The scanner I am using and have installed via cordova plugin add is
I am not currently importing the barcodescanner.js file into the html as I have done with older versions of cordova as I believe this is handled differently in 3+ and seems to be defined in the cordova_plugins.js file?
Update: As far as I am aware with the config above there does not seem to be any glaring errors popup in Eclipse.
Been trying this for a few hours now and have made a little progress but not in the right direction.
I have successfully setup an Android Cordova project which loads onto a phone and runs fine. I just cannot get the barcode scanner plugin to work in Cordova 3.1. I believe it has installed correctly but it does not appear in the config.xml, it does however appear in the cordova_plugins.js file etc.
I have this in my index.js
function clickScan() {
var scanner = cordova.require(".phonegap.plugins.barcodescanner.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);
}
);
}
Now when I press the scan button it seems to run this code but jumps straight to the success function and just displays the alert box with blank results.
The scanner I am using and have installed via cordova plugin add is https://github./wildabeast/BarcodeScanner
I am not currently importing the barcodescanner.js file into the html as I have done with older versions of cordova as I believe this is handled differently in 3+ and seems to be defined in the cordova_plugins.js file?
Update: As far as I am aware with the config above there does not seem to be any glaring errors popup in Eclipse.
Share Improve this question edited Feb 21, 2014 at 17:35 Phillip Senn 47.7k91 gold badges261 silver badges378 bronze badges asked Nov 7, 2013 at 23:15 Aaron FisherAaron Fisher 6453 gold badges9 silver badges24 bronze badges1 Answer
Reset to default 5Yes, You dont need to import any plugin specific javascript file in your index.html. Just Verify that plugin in properly installed in your project by confirming YourProject/res/config.xml file has the following entry:
<feature name="BarcodeScanner">
<param name="android-package" value=".phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>
For using the plugin, just use the updated syntax of calling the plugin functions -
function clickScan() {
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);
});}
本文标签: javascriptInstalling PhonegapCordova 31 plugins (barcodescanner)Stack Overflow
版权声明:本文标题:javascript - Installing PhonegapCordova 3.1 plugins (barcodescanner) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742089601a2420184.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论