I have javascript like this:
GameManager.prototype.restart = function () {
AndroidFunction.showMessage("Hai");
};
And to get string "Hai" in android, i can use this code and works
webView = (XWalkView) findViewById(R.id.walk_view);
webView .addJavascriptInterface(new WebAppInterface(), "AndroidFunction");
webView .loadUrl(someURL);
public class WebAppInterface {
@JavascriptInterface public void showMessage(String toast) {
Toast.makeText(PlayGameViewActivity.this, toast, Toast.LENGTH_SHORT).show();
}
}
But when i change the javascript to this:
GameManager.prototype.restart = function () {
AndroidFunction.test.showMessage("Hai");
};
There is test between AndroidFunction and showMessage, and this is my java code:
webView = (XWalkView) findViewById(R.id.walk_view);
webView .addJavascriptInterface(new WebAppInterface(), "AndroidFunction.test");
webView .loadUrl(someURL);
public class WebAppInterface {
@JavascriptInterface public void showMessage(String toast) {
Toast.makeText(PlayGameViewActivity.this, toast, Toast.LENGTH_SHORT).show();
}
}
My WebAppInterface doesn't get any message from javascript instead get error message
Uncaught TypeError: Cannot read property 'test' of undefined
, My question is how to get AndroidFunction.test.showMessage("Hai");