0

I am using a library called matrix.org

enter image description here

there are some javascript files in this library that contains some methods

is it possible to call these method inside native java or kotlin code of android studio ?

Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175

1 Answers1

0

First you have to enable JavaScript

webView.getSettings().setJavaScriptEnabled(true); 

To call JavaScript method you have to use evaluateJavascript(..) method

    webView.evaluateJavascript("javascript: " + "getValue(\"message\")", new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String value) {
            Log.i(TAG, "onReceive");
            Log.i(TAG, "Received: " + value);
        }
    });

And your JavaScript method is like

function getValue(msg) {
    return 10;
}
Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50