Calling Java Methods with JavaScript from Crosswalk

mXWalkView = (XWalkView) findViewById(R.id.activity_main);
XWalkSettings webSettings = mXWalkView.getSettings();
webSettings.setJavaScriptEnabled(true);
public class JsInterface {
	public JsInterface() {
	}
	
	@JavascriptInterface
	public String sayHello() {
		return "Hello World!";
	}
}
mXWalkView.addJavascriptInterface(new JsInterface(), "NativeInterface");
<a href="#" onclick="clicked()">Say Hello</a>
function clicked() {
    alert(NativeInterface.sayHello());
}

References
http://zhangwenli.com/blog/2014/08/25/crosswalk-calling-java-methods-with-javascript/
https://developer.android.com/guide/webapps/webview.html#BindingJavaScript
http://stackoverflow.com/questions/25478434/crosswalk-call-java-method-from-javascript

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.