0

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");

  • Why cant you you use, `AndroidFunction_Test` or `AndroidFunctionTest`. The problem is that when you call `variable.another_variable`, the first variable is considered as an object. – K Neeraj Lal May 03 '16 at 13:11
  • @K Neeraj Lal : It's because my friend using swift language and he must use `another_variable` to get or post message to javascript.. and we work with one javascript project.. – Xenix Putra Sasongko May 04 '16 at 04:22

0 Answers0