Created
December 2, 2011 20:53
-
-
Save macdonst/1424796 to your computer and use it in GitHub Desktop.
BarcodeScanner Android Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta name="viewport" content="width=320; user-scalable=no" /> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>PhoneGap</title> | |
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8"> | |
<script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script> | |
<script type="text/javascript" charset="utf-8" src="barcodescanner.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
function init(){ | |
console.log("GOT AN ONLOAD!!!") | |
document.addEventListener("touchmove", preventBehavior, false); | |
document.addEventListener("deviceready", deviceInfo, true); | |
} | |
var preventBehavior = function(e) { | |
e.preventDefault(); | |
}; | |
var deviceInfo = function(){ | |
console.log("In deviceInfo!"); | |
document.getElementById("platform").innerHTML = device.platform; | |
document.getElementById("version").innerHTML = device.version; | |
document.getElementById("uuid").innerHTML = device.uuid; | |
} | |
function scan() { | |
window.plugins.barcodeScanner.scan(function(result) { | |
alert("We got a barcode\n" + | |
"Result: " + result.text + "\n" + | |
"Format: " + result.format); | |
}, function(error) { | |
alert("Scanning failed: " + error); | |
}); | |
} | |
function encode(type, data) { | |
window.plugins.barcodeScanner.encode(type, data, function(result) { | |
alert("encode success: " + result); | |
}, function(error) { | |
alert("encoding failed: " + error); | |
}); | |
} | |
</script> | |
</head> | |
<body onload="init();" id="stage" class="theme"> | |
<h1>Welcome to PhoneGap!</h1> | |
<h2>this file is located at assets/index.html</h2> | |
<div id="info"> | |
<h4>Platform: <span id="platform"> </span></h4> | |
<h4>Version: <span id="version"> </span></h4> | |
<h4>UUID: <span id="uuid"> </span></h4> | |
</div> | |
<a href="#" class="btn large" onclick="scan();">Scan</a> | |
<a href="#" class="btn large" onclick="encode(BarcodeScanner.Encode.TEXT_TYPE, 'http://www.phonegap.com');">Encode Text</a> | |
<a href="#" class="btn large" onclick="encode(BarcodeScanner.Encode.EMAIL_TYPE, 'someone@somewhere.com');">Encode Email</a> | |
<a href="#" class="btn large" onclick="encode(BarcodeScanner.Encode.PHONE_TYPE, '1800551212');">Encode Phone</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to display genetared QR code in our app... Plz help me