安卓和H5交互 点击H5界面跳转Activity

安卓:

通过URL 加载webview控件;

wv.loadUrl("file:///android_asset/index.html");

@JavascriptInterface

publicvoidtoActivity(String activityName) { //和H5端定义一个统一的方法名重新

//此处应该定义常量对应,同时提供给web页面编写者

if(TextUtils.equals(activityName,"a")){

startActivity(new Intent(this,AActivity.class));

}else{

startActivity(new Intent(this,BActivity.class));

}

}

H5:

<html>

<scripttype="text/javascript">

functiongotoActivity (activity) {

nativeMethod.toActivity(activity); //H5端调用的方法

}script>

<body>

<buttononClick="gotoActivity('a')">gotoActivity Abutton>

<buttononClick="gotoActivity('b')">gotoActivity Bbutton>

body>html>


你可能感兴趣的:(安卓和H5交互 点击H5界面跳转Activity)