【问题标题】:Installing Phonegap/Cordova 3.1 plugins (barcodescanner)安装 Phonegap/Cordova 3.1 插件 (barcodescanner)
【发布时间】:2013-11-07 23:15:43
【问题描述】:

现在已经尝试了几个小时并取得了一些进展,但方向不正确。

我已经成功设置了一个 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 中弹出任何明显的错误。

【问题讨论】:

    标签: javascript android cordova phonegap-plugins


    【解决方案1】:

    是的,您不需要在 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);
      });}
    

    【讨论】:

    • 经过仔细检查,我将它放在 Res 文件夹中,我意识到我错过了一些不是立即显而易见的步骤。我需要从根文件夹运行构建命令,这会将插件推送到所有平台,感谢您的帮助!
    • 这对我来说不适用于科尔多瓦 3.3.1-0.1.2。更新语法到底是什么意思?这是一个未记录的更改吗?如果是这样,你能指出我的来源吗?在开发者文档中,语法是 cordova.exec('') cordova.apache.org/docs/en/3.3.0/…
    • 我认为它指的是barcodescanner api语法:它从var scanner = window.cordova.require("cordova/plugin/BarcodeScanner"); scanner.scan(function (result) {}, function (error) {}); }传递到简单的window.plugins.barcodeScanner,最后到cordova.plugins.barcodeScanner
    猜你喜欢
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多