Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我看过这篇文章:- 将数据从java类传递到Web View html
我们可以将字符串从 android 函数返回到 android 应用程序 webview 中的 html 文件吗?
您可以实现一些返回此类字符串的 Java 类:
public class Bar { public String foo() { return "bla-bla-bla"; } }
之后,您将其传递给 addJavascriptInterface 方法:
webView.addJavascriptInterface(new Bar(), "bar");
现在你有了 JavaScript 对象“bar”:
alert(bar.foo());