javascript - 如何在 Phonegap 中扫描二维码

标签 javascript cordova phonegap-plugins

我开始使用 phonegap,我在 phonegap 中学习了很多插件,但是当我想在 phonegap 中使用 QR 扫描仪时,我遇到了困难。有的话给我解决办法

最佳答案

不久前曾在我的 cordova 应用程序中尝试过此 QR 码扫描。希望它能正常工作。代码如下:

index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <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" />
        <title>QR Scanner</title>
    </head>
    <body>        
        <script type="text/javascript" src="cordova.js"></script>   
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/app.js"></script>
        Click scan button to scan the QR code: <input type="button" value="scan" name = "scan" id="scan"/>
    </body>
</html>

app.js

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {      
     $('#scan').click( function() 
        {
          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);
          });
        }
     );
}

确保从phonegap-plugin-barcodescanner link添加jquery库js文件和QR码扫描插件试用此示例。

关于javascript - 如何在 Phonegap 中扫描二维码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37983058/

相关文章:

ios - Cordova和iOS 8:状态栏处于隐藏状态

ios - 如何使用 phone gap 创建 apple watch 项目

php - ajax - 如何执行一组特定的 AJAX 代码而不执行其他代码

javascript - 为什么我的 js 脚本根据所述字段中的字符数量而不是一次创建多个选项标签?

javascript - 获取选定文本javascript的边界矩形

ios - 如何在 Cordova App 中打包 Watch App

android - "cordova platform add android"错误

sqlite - 如何在 Ripple 中使用 Sqlite 运行 PhoneGap 应用程序?

iphone - PhoneGap/iOS - 如何让 Childbrowser 忽略指向 Appstore 的链接?

javascript - 悬停时在容器/页面底部显示隐藏段落