Java and js methods are used for interdebugging and are often used when HTML5 is used for cross-platform application development. Here, I will share some of my usage in the actual development process, hoping to help beginners.
When using HTML5 for cross-platform application development, it may be difficult for beginners to try the problem that java and js methods are used for interdebugging, here we will share some of your usage in the actual development process, hoping to help you:
First, the js Code calls java code introduction:
Copy codeThe Code is as follows:
Public class CzingLBWebMain extends DroidGap {
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
This. loadUrl (file: // android_asset/www/czingIndexHome.html );
WebSettings webSettings = this. appView. getSettings ();
WebSettings. setLoadWithOverviewMode (true );
WebSettings. setSavePassword (false );
WebSettings. setSaveFormData (false );
WebSettings. setsuppzoom zoom (false );
WebSettings. setAllowFileAccess (true );
WebSettings. setJavaScriptEnabled (true );
WebSettings. setPluginState (WebSettings. PluginState. ON );
// Add a java instance to js so that js Code can call java code
This. appView. addJavascriptInterface (this, "appDownloader ");
}
Public void callBackJava (){
}
}
Then, you can directly call the preceding callBackJava () method through window. appDownloader. callBackJava () in the js file referenced by czingindexhome.html.
Then how to call js Code through java code:
The following method is used in java:
Copy codeThe Code is as follows:
String resUrl = "aa ";
String resId = "bb ";
String callBack = "javascript: callBackServive ('" + resUrl + "', '" + resId + "')"; // note the method for passing more than two parameters
This. appView. loadUrl (callBack );
CallBackServive is implemented in js.