Monday, 13 May 2019

triggering JavascriptInterface from a 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);
    }

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 ?



from triggering JavascriptInterface from a android webview

No comments:

Post a Comment