现在已经尝试了几个小时,取得了一些进展,但方向不对。
我已经成功设置了一个 Android Cordova 项目,它可以加载到手机上并运行良好。我只是无法让条形码扫描器插件在 Cordova 3.1 中工作。我相信它已正确安装,但它没有出现在 config.xml 中,但它确实出现在 cordova_plugins.js 文件等中。
我的 index.js 里有这个
function clickScan() {
var scanner = cordova.require("com.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);
}
);
}
现在,当我按下扫描按钮时,它似乎运行了这段代码,但直接跳转到成功函数,只显示带有空白结果的警告框。
我正在使用并通过 cordova 插件添加安装的扫描仪是 https://github.com/wildabeast/BarcodeScanner
我不目前将barcodescanner.js文件导入到html中,就像我对旧版本的cordova所做的那样,因为我相信这在3+中的处理方式不同并且似乎在cordova_plugins中定义.js 文件?
更新:据我所知,上面的配置在 Eclipse 中似乎没有弹出任何明显的错误。
最佳答案
是的,您不需要在 index.html 中导入任何插件特定的 javascript 文件。 只需通过确认 YourProject/res/config.xml 文件具有以下条目来验证插件是否已正确安装在您的项目中:
<feature name="BarcodeScanner">
<param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>
要使用插件,只需使用调用插件函数的更新语法 -
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);
});}
关于javascript - 安装 Phonegap/Cordova 3.1 插件 (barcodescanner),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19848671/