将数据从java类传递到Web View html
I'm loading below html in my webView
我在我的webView中加载到html下面
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
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.
现在我想做的是填充来自我的java类变量的html中的文本框,然后自动点击提交。
But I don't have any idea how to do this.
但我不知道该怎么做。
Any thougths will be appreciated.
任何人都会受到赞赏。
5 个解决方案
#1
37
First, your URL seems not available.
首先,您的网址似乎不可用。
If you want to do data exchange between android app and your web app/web page you can achieve this via javascript.
如果你想在Android应用程序和你的网络应用程序/网页之间进行数据交换,你可以通过javascript实现这一点。
Here is an example from Android official site:
以下是Android官方网站的示例:
Create a class like this:
创建一个这样的类:
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();
}
}
In your WebView
:
在您的WebView中:
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
In your web page:
在您的网页中:
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
If you wanna pass something to your webpage, just calling corresponding javascript function:
如果你想传递一些东西到你的网页,只需调用相应的javascript函数:
String str = "xxx";
myWebView.loadUrl("javascript:xxx('"+str+"')");
Here is the Reference: http://developer.android.com/guide/webapps/webview.html
以下是参考:http://developer.android.com/guide/webapps/webview.html
更多相关文章
- Java Android套接字连接。错误的IP地址导致应用程序停止响应
- Android 为你的应用程序添加快捷方式【优先级高的快捷方式】
- 添加脚本到Android应用程序
- 如何使用java RESTful Web服务将通知推送到Android应用程序
- android 获取正在运行的应用程序列表
- 如何开始为Android开发应用程序? [重复]
- Android Web-View:将本地Javascript文件注入远程网页
- 王家林最受欢迎的一站式云计算大数据和移动互联网解决方案课程 V
- 当在调试模式下启动时,Android应用程序崩溃。