mcf*_*oft 7 javascript java android webview
I followed an instruction to trigger the JavascriptInterface from a webview, but it isnt triggered in my case.
I have an class QuickTextViewer with following:
public class QuickTextViewer {
private WebView webView;
...
...
public QuickTextViewer(){
webView = dialog.findViewById(R.id.mywebview);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:MyApp.resize(document.body.getBoundingClientRect().height)");
super.onPageFinished(view, url);
}
}
@JavascriptInterface
public void resize(final float height) {
System.out.print(height);
}
Run Code Online (Sandbox Code Playgroud)
I also added the following to proguard-rules.pro (actually public only for testing)
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
Run Code Online (Sandbox Code Playgroud)
就我而言,触发了onPageFinished,但没有resize()!有任何建议/帮助吗?
现在发现了问题。只需添加:
webView.getSettings().setJavaScriptEnabled(true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |