java:
//可以处理一些由android控制的信息
public class GetHtmlInfo{
public String getContent(String str){
String res = "hello"+str;
return res;
}
}
//添加JS调用webview的方法
GetHtmlInfo ghi =new GetHtmlInfo();
webView.addJavascriptInterface(ghi,"demo");
html中:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" />
</head>
<body id="myBody">
</body>
<script>
window.demo.getContent();
</script>
</html>