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> |
Yeah, the success function of encode never gets called. The encode function never seems to call onActivityResult.
Exactly , i checked out the native code . it isn't calling onActivityResult.so it is not possible to get callback in encode function in android.
how to display genetared QR code in our app... Plz help me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Macdonst ,
Nice demo .
i have implemented the same and not getting success callback from function encode though i can see encoded image in different screen successfully..
I have crossed check many times the phonegap versions and all other things but cant figure it out.
My question is just i would like to know that if you are getting alert("encode success: " + result) or not .. ?