7

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);
    }

I also added the following to proguard-rules.pro (actually public only for testing)

-keepclassmembers class fqcn.of.javascript.interface.for.webview {
   public *;
}

In my case onPageFinished is triggered but resize() not ! Any suggestions/help ?

1
  • found the problem: had to add webView.getSettings().setJavaScriptEnabled(true); Commented May 12, 2019 at 15:41

1 Answer 1

5

Found the problem now. Just had to add:

webView.getSettings().setJavaScriptEnabled(true);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.