In the use of HTML5 to do cross-platform application development, taste will use Java and JS method intermodulation problem, for beginners, it may be a little difficult, here to share some of their own in the actual development of the use, I hope to help you:
First, the JS code calls Java code Introduction:
Copy Code code 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.setsupportzoom (FALSE);
Websettings.setallowfileaccess (TRUE);
Websettings.setjavascriptenabled (TRUE);
Websettings.setpluginstate (WebSettings.PluginState.ON);
Add a Java instance to JS so that the JS code calls Java code
This.appView.addJavascriptInterface (This, "Appdownloader");
}
public void Callbackjava () {
}
}
You can then invoke the Callbackjava () method directly in the JS file referenced by czingindexhome.html directly via Window.appDownloader.callBackJava ().
And then how to call the JS code through Java code:
This is done in Java in the following ways:
Copy Code code as follows:
String resurl= "AA";
String resid= "BB";
String callback= "javascript:callbackservive (' +resurl+" ', ' "+resid+") "//Note the method of passing more than two parameters
THIS.APPVIEW.LOADURL (CallBack);
Callbackservive is the way to implement in JS.