【问题标题】:Return string from an android method to the html file, from webview [closed]从 android 方法返回字符串到 html 文件,从 webview [关闭]
【发布时间】:2013-03-17 03:55:50
【问题描述】:

我看过这篇文章:- Passing data from java class to Web View html

我们可以从一个android函数返回字符串到android应用程序的webview中的html文件吗?

【问题讨论】:

  • 你的主题和内容完全一样,你能澄清一下你的期望吗?

标签: android


【解决方案1】:

您可以实现一些返回此类字符串的 Java 类:

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

然后将其传递给 addJavascriptInterface 方法:

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

现在你有了 JavaScript 对象“bar”:

alert(bar.foo());

【讨论】:

  • 谢谢。我会竖起大拇指的,但我没有 15 名声望。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-23
  • 1970-01-01
  • 2016-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多