1.new 一个webview
webView.addJavascriptInterface(new ShareJs(mContext), "cmtJsInterface");
其中 WebAppInterface是个类 类中 有个空的构造方法,例如:
public class ShareJs {Context mContext;
public ShareJs(Context mContext) {
this.mContext = mContext;
}
@JavascriptInterface //sdk17版本以上加上注解
public void jumpApp(String name) {
Toast.makeText(mContext, name, Toast.LENGTH_LONG).show();
}
}
2.把对象和方法名 交给html ,在html中里的代码 如下:
3.至此完成了html5页面调用Android本地的方法。