Barcode Scanner JavaScript Functions

You can find the JavaScript test page at https://www.android-kiosk.com/jstest.htm Just set this as the Kiosk URL on your device to test the functions.

Open Barcode Scanner (without data)
Opens barcode scanner activity.

<script>
function openAndroidBarcodeScanner() {
Android.openBarcodeScanner();
}
</script>
<a href="javascript:openAndroidBarcodeScanner();">Open Barcode Scanner - without data</a>


Open Barcode Scanner (with data)
Opens barcode scanner activity with data which is returned with scanned barcode data.

<script>
function openAndroidBarcodeScannerData(data) {
Android.openBarcodeScanner(data);
}
</script>
<a href="javascript:openAndroidBarcodeScannerData('test=1');">Open Barcode Scanner - with data</a>


Open Barcode Scanner (with input field ID)
Opens barcode scanner activity with ID of input field, scanned data is returned to the supplied input field. Optionally you may use the onchange event to trigger a custom function. Requires version 2.0.7 or higher.

<script>
function openAndroidBarcodeScannerInput(input) {
Android.openBarcodeScannerInput(input);
}
function onTestInputChange() {
alert('.change() for testinput, value = ' + $('#testinput').val());
}
</script>
<a href="javascript:openAndroidBarcodeScannerInput('testinput');">Open Barcode Scanner - input field ID</a><input type="text" id="testinput" value="" onchange="onTestInputChange()">

<!--ALTERNATIVE METHOD, TAP INPUT FIELD-->
<input type="text" id="testinput2" value="Scan Barcode (Tap to test)" onClick="javascript:openAndroidBarcodeScannerInput(this.id);" readonly><br/>


Open Barcode Scanner (with input field ID)
Opens barcode scanner activity and returns scan result to JavaScript function barcodeScanResult(data). Requires version 2.6.6 or higher.

<script>
function openBarcodeScannerResultCallback() {
Android.openBarcodeScannerResultCallback();
}

function barcodeScanResult(data) {
console.log("Result Data: " + data);
}
</script>
<a href="openBarcodeScannerResultCallback();">Open Barcode Scanner Callback Result</a>


Zebra Barcode Scanner
Register for the barcode scan callback. Once registered each scan result is sent via barcodeScanResult(data). This callback PERSISTS page loads, so you may need to unregister the callback on other pages if you do not always want the results to be fed back to you via JavaScript (use false as parameter). Requires version 2.6.6 or higher.

<script>
function registerForBarcodeScanResults() {
if (typeof Android != 'undefined') {
//tell KB to return results via JS function
Android.useJavaScriptCallbackZebraScanner(true);
}
}

function barcodeScanResult(data) {
console.log(data);
}
</script>


Generic Barcode Scanner Device (wepoy etc...)
Register for the barcode scan callback. Once registered each scan result is sent via barcodeScanResult(data). This callback PERSISTS page loads, so you may need to unregister the callback on other pages if you do not always want the results to be fed back to you via JavaScript (use false as parameter). Requires version 2.6.6 (build 230) or higher.

<script>
function registerForBarcodeScanResults() {
if (typeof Android != 'undefined') {
//tell KB to return results via JS function
Android.useJavaScriptCallbackGenericScanner(true);
}
}

function barcodeScanResult(data) {
console.log(data);
}
</script>
Was this article helpful?
Thank you!