Anu*_*mar 1 javascript phonegap-plugins cordova
我正在开始使用phonegap,我在phonegap中学习了许多插件,但是当我想在phonegap中使用QR扫描仪时,我会陷入困境.如果有,给我任何解决方案
我曾经在我的cordova应用程序中尝试过这个二维码扫描.希望它应该工作正常.代码如下:
的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>
Run Code Online (Sandbox Code Playgroud)
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);
});
}
);
}
Run Code Online (Sandbox Code Playgroud)
确保从phonegap-plugin-barcodescanner链接添加jquery库js文件和QR代码扫描程序插件以试用此示例.