How to insert a row in Android WebView
I am loading a simple webpage with a text box named "AddSerialNum"
<form> Serial Number: <input type="text" name="AddSerialNum"> </form> Then I try to fill in this field, the line that I get from the result of scanning a barcode 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 fucking results in the box! browser.loadUrl("javascript:document.getElementByID('AddSerialNum').value = '"+contents+"';"); } else if (resultCode == RESULT_CANCELED) { // Cancellation action } } } A notification about the toast appears and the serial number of the barcode is copied to the clipboard as the main clip, but why doesnโt it fill out the form in the html file?
It seems to me that I'm missing something, but I have tired eyes, and this upsets me. Does anyone know how to help?
Thanks in advance!
I found the answer myself.
Use the following code.
browser.loadUrl("javascript:document.forms[0].AddSerialNum.value = '"+contents+"';"); It seems that you need to go to this field with nodes, and not just the final field.