在Android App里,选择好参数,点击App内的一个Button后,
把参数传到部署在服务器上的html,html显示查询结果,该怎么实现呢?
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>测试</title>
<script type="text/javascript">
function Myonclick() {
alert("触发了onclick事件!");
}
function del() {
alert("OK");
}
function showFromHtml() {
document.getElementById("id_input").value = "Java call Html";
}
function showFromHtml2(param) {
document.getElementById("id_input2").value = "Java call Html : " + param;
}
function JavacallHtml2(param) {
document.getElementById("id_input2").value = "Javas call Html : " + param;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="HtmlcallJava" onclick="showFromHtml()" />
<input type="button" value="HtmlcallJava2" onclick="showFromHtml2()" />
<input id="id_input" style="width: 90%" type="text" value="null" />
<br />
<input type="button" value="JavacallHtml" onclick="window.jsObj.JavacallHtml()" />
<br />
<input id="id_input2" style="width: 90%" type="text" value="null" />
<br/>
<input type="button" value="JavacallHtml2" onclick="window.jsObj.JavacallHtml2()" />
</form>
</body>
</html>
Android
private static final String url = "http://xx.xx.x.xx/test/index.aspx";
private WebView mWebView;
private String Msg = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
Intent intent = getIntent();
Msg = intent.getStringExtra("jobno");
initView();
}
private void initView() {
mWebView = (WebView) findViewById(R.id.web);
mWebView.setWebChromeClient(new WebChromeClient());
//或的WebView的Setting
WebSettings settings = mWebView.getSettings();
//设置支持js,看方法名字就知道啥意思
settings.setJavaScriptEnabled(true);
settings.setDefaultTextEncodingName("GBK");//设置字符编码
mWebView.setScrollBarStyle(0);//滚动条风格,为0指滚动条不占用空间,直接覆盖在网页上
mWebView.loadUrl("javascript:showInfoFromJava('" + Msg + "')");
//加载网页路径
mWebView.loadUrl(url);
}
上面的代码测试,无法获得从App传到THML的参数!