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 openAndroidBarcodeScannerResultCallback() {
Android.openAndroidBarcodeScannerResultCallback();
}

function barcodeScanResult(data) {
console.log("Result Data: " + data);
}
</script>
<a href="openAndroidBarcodeScannerResultCallback();">Open Barcode Scanner Callback Result</a>
Was this article helpful?
Thank you!