您的位置:首页 > 移动开发 > Android开发

android 调用webview控件,为逆向h5app做准备

2018-01-15 17:02 483 查看
activity对应layout文件加入:

<WebView
android:id="@+id/main_web"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>


activity代码 :

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWeb = (WebView)findViewById(R.id.main_web);
mWeb.getSettings().setJavaScriptEnabled(true);

//覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开
mWeb.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
view.loadUrl(url);
return true;
}
});


以下为5.1机器上测试,js无法调用未导出的组件方法,

hello为导出的类对象。不知道大神是用的什么方法调起来的


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">

function test()
{
ob1=window.hello
if(ob1!=null)
{
cls=ob1.getClass()

if(cls==null)
{
return
}

rt=cls.forName("java.lang.Runtime")

if(rt!=null)
{
rt.getMethod("getRuntime").invoke().exec("echo 111");
}

}
}

</script>

<title></title>
</head>
<body>
<input type="button" value="返回安卓的某一个界面" onclick="test()"/>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: