Odk-x use intent to scan barcode in html page

Hello everyone,

I have HTML page like Geotagger where I can Search in the list using input text,
But I want to make a button where I can use the zxing barcode.
so I can easily find what I want from the list.
how can I make Intent in the javascript?
can anybody help me?


You can use the odkcommon.js injected interface to launch an intent using the odkCommon.doAction function.

Brief example:

    $('#barcode').on('click', function() {
        var dispatchStruct = JSON.stringify({actionTypeKey: actionBarcode,
            htmlPath:htmlFileNameValue, userAction:userActionValue});

        odkCommon.doAction(dispatchStruct, 'com.google.zxing.client.android.SCAN', null);

hello @W_Brunette
I did use the odkcommon.js to launch an intent but I can not receive data back .

window.addEventListener(“load”, function () {
function () {
alert(“inside the listener”);
var action = odkCommon.viewFirstQueuedAction();
$("#searchForText").val(“inside the listener”);
if (action !== null) {
var dispatchStruct = action.dispatchStruct;
if (dispatchStruct && dispatchStruct.userAction == “scan-kast-code”) {
var jsonValue = action.jsonValue;
$("#searchForText").val(“status = " + jsonValue.status);
if (jsonValue.status === 0) {
// process action – be idempotent!
// if processing fails, the action will still
// be on the queue.
$("#barcode").click(function () {
var dispatchStruct = { userAction: “scan-kast-code” };
var intentArgs = {
// extras: extrasBundle,
// uri: // set the data field of intent to this
// data: // unless data is supplied – that takes precedence
// type: // set the intent type to this value
// package: // set the intent package to this value

    return odkCommon.doAction(dispatchStruct,


the registerListener doesn’t work or i don’t know how to use it.

Can you check with me, please.

There are a few issues with your listener:

  1. action.dispatchStruct is a JSON string, you need to parse it to read its content.
  2. action.jsonValue.status is expected to be -1
  3. The result of the scan is stored in action.jsonValue.result.SCAN_RESULT

If the issue is that the listener isn’t being called at all, try calling your listener right after registering it.