简体   繁体   English

barcodescanner phonegap插件问题

[英]barcodescanner phonegap plugin issue

I'm currently trying to implement barcodescanner in my phonegap project. 我正在尝试在我的phonegap项目中实现barcodescanner。 But I'm completly lost because I read a lot of topics about barecodescanner and all possible solutions provided didn't work for me. 但是我完全迷失了,因为我读了很多关于裸码扫描的话题,所提供的所有可能解决方案对我都不起作用。

First, some tutorials and documents says that I have to use cordova.plugin.barcodeScanner.scan (...). 首先,一些教程和文档说我必须使用cordova.plugin.barcodeScanner.scan(...)。 But for me, cordova.plugin is always undefined. 但对我来说,cordova.plugin总是未定义的。

Some others says that I have to do cordova.require("cordova/plugin/BarcodeScanner"); 其他人说我必须做cordova.require(“cordova / plugin / BarcodeScanner”); and it doesn't work, when I run my app, I get the following error : "module "cordova/plugin/BarcodeScanner" not found. 并且它不起作用,当我运行我的应用程序时,我收到以下错误:“模块”cordova /插件/ BarcodeScanner“未找到。

If you use PhoneGap Build... This is an example of implementation... 如果你使用PhoneGap Build ...这是一个实现的例子......

In the config.xml file add this line: 在config.xml文件中添加以下行:

<!-- We'll include the Barcode plugin  -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" />

Then in the index.html file: 然后在index.html文件中:

<script type="text/javascript">
function Scan() {
    cordova.plugins.barcodeScanner.scan(
      function (result) {
          window.open(result.text,'_self', 'location=no') //Opens URL in browser
          //alert("We got a barcode\n" +
          //      "Result: " + result.text + "\n" +
          //      "Format: " + result.format + "\n" +
          //      "Cancelled: " + result.cancelled);
      }, 
      function (error) {
          alert("Scanning failed: " + error);
      }
    );
}
</script>

To call the script with a button in the body section of page: 要使用页面正文部分中的按钮调用脚本:

<button onclick="Scan()">Barcode</button>

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM