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.
我有几个活动,需要访问 JS 代码,在 WebView 中运行。我需要那个 JS 代码和它的状态可以从任何地方访问,所以我想也许我可以在我的应用程序类中运行 Webkit 引擎,并将数据从它提供给 webview 和我的应用程序的其他组件?
如何将所有一般可访问状态移动到您使用 javascript 桥注册的 java 中的 javascript 接口:
webView.addJavascriptInterface(new JsBridge(), "jsbridge");
我使用它来将数据从 javascript 传输到我的 android/java 代码并返回。它没有提供访问所有数据的通用接口,但也许这仍然足够。