-3

I have seen this article:- Passing data from java class to Web View html

Can we return string from an android function to the html file in the webview of the android application.

Community
  • 1
  • 1
user1825567
  • 153
  • 1
  • 9

1 Answers1

2

You can implement some Java class returning such string:

public class Bar {
  public String foo() {
    return "bla-bla-bla";
  }
}

After that you pass it to addJavascriptInterface method:

webView.addJavascriptInterface(new Bar(), "bar");

Now you have JavaScript object "bar":

alert(bar.foo());
stefan.nsk
  • 1,755
  • 1
  • 16
  • 12