如何在Android平台的phonegap中集成条码扫描器? [英] how to integrate barcode scanner in phonegap in android platform?

查看:122
本文介绍了如何在Android平台的phonegap中集成条码扫描器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的PhoneGap应用程序中集成 barcodescanner 功能,但在运行我的应用程序时遇到问题未找到类或applicationcontent在applicationstatus中丢失。 / code>

I want to integrate a "barcodescanner"-feature into my PhoneGap Application, but facing problem while running my app "class not found or applicationcontent is missing in applicationstatus.

这是我的 index.html 档案

<html>
    <head>

        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">

         <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <title>Hello World</title>
        <script type="text/javascript">
         document.addEventListener("deviceready",onDeviceReady,false);

         function onDeviceReady(){

         }
          cordova.plugins.barcodeScanner.scan(
      function (result) {
      alert("hello");
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
      }, 
      function (error) {
          alert("Scanning failed: " + error);
      }
   );
          cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
            alert("encode success: " + success);
          }, function(fail) {
            alert("encoding failed: " + fail);
          }
        );

        </script>
    </head>
    <body>
    <button id="btn" onclick="scan()">scan</button>
     <button id="btn1" onclick="encode()">edit text</button>

    </body>
</html>

谢谢

推荐答案

我只是测试它并且工作正常:

I just tested it and works fine :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
</head>
<body>

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

    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script>
    function scanBarcode(){

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);
  }
 );
}

    </script>

</body>
</html>

您的代码的问题是,您没有scan()和encode绑定到您的按钮,因此什么也不会发生。

The issue with your code is that you don't have functions scan() and encode() to bind to your buttons thus nothing will happen.

这篇关于如何在Android平台的phonegap中集成条码扫描器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆