1

I am loading a simple webpage, with a Text Field named "AddSerialNum"

<form>
Serial Number: <input type="text" name="AddSerialNum">
</form>

Then I am trying to populate that field, with a string I get from a barcode scan result in Android:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        String contents = null;
        //Call Clipboard and assign service to var. 
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                //Set contents = to scan result
                contents = data.getStringExtra("SCAN_RESULT");
                //Format scan result
                @SuppressWarnings("unused")
                String format = data.getStringExtra("SCAN_RESULT_FORMAT");
                //Copy Data to clipboard
                ClipData clip = ClipData.newPlainText("serial", contents);
                clipboard.setPrimaryClip(clip); 
                //Toast - message states copy was successful with serial number
                Toast.makeText(this, "Copied " +contents , Toast.LENGTH_LONG).show();


                // Handled a successful scan

                //Put the results in the box!
        browser.loadUrl("javascript:document.getElementByID('AddSerialNum').value = '"+contents+"';");


            } else if (resultCode == RESULT_CANCELED) {
                // Cancellation action
            }
        }
    } 

The toast notification comes up, and the serial number of the barcode is copied to the clipboard as a primary clip, But why is it not filling in the form on the html file?

I feel like I am missing something, but I have tired eyes, and this is frustrating me. Anyone know how to help?

Thanks in advance!

Danny06191
  • 133
  • 1
  • 9

1 Answers1

3

Found the answer myself.

The following code should be used.

browser.loadUrl("javascript:document.forms[0].AddSerialNum.value = '"+contents+"';");

It seems that you have to navigate to that field by nodes, rather than just the final field.

Danny06191
  • 133
  • 1
  • 9