0

My application needs to retrieve data from a web site. I use a webview to access the required page. In the page displayed in this webview there are links leading to the detailed info that the app needs. When following a link (using the webView.loadUrl()) a popup is displayed on top of the webview.

The app gets access to the links with the following code:

    webView.getSettings().setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new BackgroundScriptInterface(), "HTMLOUT");
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url)
        {
            webView.loadUrl("javascript:window.HTMLOUT.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
        }
    });

and

public class BackgroundScriptInterface {
    @JavascriptInterface
    public void processHTML(String html) {
        ...
    }

But this BackgroundScriptInterface is not called when a popup displays.

How do I get access to the html contents of the popup?

EDIT As suggested by Eddie below, I've tried

    webView.evaluateJavascript(item.competDetailUrl, new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String s) {
            Log.d("competDetail", s);
        }
    });

The popup is still displayed as expected. However the value passed to the onReceiveValue callback is "null".

ema3272
  • 1,021
  • 2
  • 13
  • 28

2 Answers2

0

Try using webView.evaluateJavascript() instead of webView.loadUrl(), unless you need to work with pre-Kitkat devices

Reference: Android Calling JavaScript functions in WebView

Eddie
  • 11
  • 2
0

The info the app retrieves from that site do not need to be displayed on the UI. They are parsed and used in the app logic. Hence I have designed the following work-around: I have replaced the original javascript:apex.navigation.dialog() by a javascript:apex.navigation.redirect() that displays the requested info directly into the webview instead of into a popup window.

As the info now comes into the webview, it can be accessed by the above BackgroundScriptInterface.

ema3272
  • 1,021
  • 2
  • 13
  • 28