Java and JS Code intermodulation sample Code _java

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.