0

I'm trying to listen to url changes from a WebView client and just log the updates. I'm navigating through my webView and shouldOverrideUrlLoading() is never called. I don't know why.

Here is my code :

public class WebViewActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        Intent i = getIntent();
        String url= i.getStringExtra("url");
        webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                String currentUrl = url;
                Log.i("currentUrl",": " + currentUrl);
                view.loadUrl(url);

                return true;
            }
        });
        webView.loadUrl(url);
    }

}

Mathieu Rios
  • 350
  • 1
  • 17
  • Possible duplicate of https://stackoverflow.com/questions/36484074/is-shouldoverrideurlloading-really-deprecated-what-can-i-use-instead – Robert Apr 29 '21 at 12:53
  • I didn't find any answer to my issue in this thread. – Mathieu Rios Apr 29 '21 at 12:56
  • 1
    The answers clearly show that there are two methods you have to implement, you have only implemented the old deprecated method `shouldOverrideUrlLoading()`. – Robert Apr 29 '21 at 13:04
  • I tried to implement the two methods, then one at a time, neither one was logging something to the console. – Mathieu Rios Apr 29 '21 at 13:09
  • It seems that the boolean is working well though. I wonder why my Log function isn't working. – Mathieu Rios Apr 29 '21 at 13:12

0 Answers0