【发布时间】:2017-08-08 01:06:03
【问题描述】:
我正在尝试通过我的移动应用程序使用 Javascript 注入将数据从应用程序传递到我的 web 视图的字段。我有一个网站表单,其中包含姓名、电子邮件等字段。姓名和电子邮件以及所有其他信息都在我的本地移动应用程序中。我想将该相关信息传递给相应的 Web 表单字段。这可能吗?以下是我尝试过的。
wv = (WebView) mRootView.findViewById(R.id.wv_help);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do nothing
}
@SuppressWarnings("deprecation")
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// do nothing
}
@TargetApi(android.os.Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, @NonNull WebResourceRequest req, @NonNull WebResourceError err) {
// do nothing
}
});
String htmlValue = "<html xmlns=\"https://my_web_form.com\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>Lorem Ipsum</title></head><body style=\"width:300px; color: #00000; \"><p><strong> About us</strong> </p><p><strong> Lorem Ipsum</strong> is simply dummy text</p></body></html>";
wv.loadDataWithBaseURL("https://my_web_form.com", htmlValue, "text/html; charset=utf-8", "UTF-8", "");
上述代码的结果是带有元数据的空白屏幕。我希望能够将元数据文本添加到我的网络表单上的特定字段。
【问题讨论】:
-
如果您要投反对票,请解释您的理由。我提出的问题是合法的,并且遵循 SO 规则/标准。
标签: javascript android webview