使用WebViwe来进行整合
<WebView
android:id="@+id/wv_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="MissingConstraints" />
webView = (WebView)root.findViewById(R.id.wv_webview);
//设置开启js调用
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
//加载h5地址
webView.loadUrl(url);
//监听跳转地址
webView.setWebViewClient(new WebViewClient(){
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
super.doUpdateVisitedHistory(view, url, isReload);
}
});
//设置和h5调用的对象 instance(新建类)
webView.addJavascriptInterface(instance, "android");
//注解申明和h5调用(这里只能返回字符串)
@JavascriptInterface
public String back() {
JSONObject jsonObject = new JSONObject();
return jsonObject.toJSONString();
}
h5端直接 window.android.back();即可调用