# andriodh5debug **Repository Path**: studyapp/andriodh5debug ## Basic Information - **Project Name**: andriodh5debug - **Description**: andriod h5 互调调试项目 debug - **Primary Language**: Android - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-12-17 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # andriodh5debug #### 介绍 andriod h5 互调调试项目 debug #### 软件架构 软件架构说明 #### andriod 部分写法 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = findViewById(R.id.web_view); WebSettings webSettings = mWebView.getSettings(); //支持javascript webSettings.setJavaScriptEnabled(true); // 通过addJavascriptInterface()将Java对象映射到JS对象 //参数1:Javascript对象名 //参数2:Java对象名 mWebView.addJavascriptInterface(new JSTest(), "test");//AndroidtoJS类对象映射到js的test对象 // 加载JS代码 // 格式规定为:file:///android_asset/文件名.html mWebView.loadUrl("file:///android_asset/index.html"); // mWebView.loadUrl("http://test.xiayuanst.com"); // mWebView.loadUrl("http://192.168.2.171:9089"); } public class JSTest { // 定义JS需要调用的方法 // 被JS调用的方法必须加入@JavascriptInterface注解 @JavascriptInterface public void setToken(String msg) { System.out.println(msg); Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_LONG).show(); } //退出 @JavascriptInterface public void loginOut() { // TODO finish(); } } } #### h5部分代码 test为andriod定义的对象 #### 参与贡献