从Java类将数据传递到Web查看HTML [英] Passing data from java class to Web View html
问题描述
我在我的web视图加载这个网站
I'm loading this html in my web view
<$c$c>https://mail-attachment.googleusercontent.com/attachment/?ui=2&ik=25c0c425c6&view=att&th=138db54ff27ad34b&attid=0.1&disp=inline&realattid=f_h5ahtmbe0&safe=1&zw&saduie=AG9B_P9YNooGjsk_jLefLptQ9q15&sadet=1343790299575&sads=-yBVsLKP_2mh7zMfYLCF7sL1u-w$c$c>
现在我想要做的是填写的是来自我的Java类变量,然后自动点击提交的HTML文本框。
now what I want to do is to fill the textbox in the html that came from my java class variable and then automatically hit submit.
但我没有任何想法如何做到这一点。
But I don't have any idea how to do this.
任何thougths将AP preciated。
Any thougths will be appreciated.
推荐答案
首先,你的URL看起来不具备的。
First, your URL seems not available.
如果你想要做的Android应用程序和Web应用程序/网页之间的数据交换,你可以通过javascript实现这一点。
If you want to do data exchange between android app and your web app/web page you can achieve this via javascript.
下面是Android的官方网站的例子:
Here is an example from Android official site:
创建一个类是这样的:
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
在你的的WebView
:
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
在您的网页:
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
如果你想传递的东西到您的网页,只需调用相应的JavaScript函数:
If you wanna pass something to your webpage, just calling corresponding javascript function:
String str = "xxx";
myWebView.loadUrl("javascript:xxx('"+str+"')");
下面是参考: <一href="http://developer.android.com/guide/webapps/webview.html">http://developer.android.com/guide/webapps/webview.html
这篇关于从Java类将数据传递到Web查看HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!