我正在加载一个简单的网页,其中包含一个名为“AddSerialNum”的文本字段
<form>
Serial Number: <input type="text" name="AddSerialNum">
</form>
然后,我尝试使用从 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
}
}
}
toast通知上来,条码的序列号作为主clip复制到剪贴板,但是为什么html文件上的表格不填呢?
我觉得我错过了一些东西,但我的眼睛很累,这让我很沮丧。有谁知道如何提供帮助?
提前致谢!