shouldOverrideUrlLoading in WebView for Android not running

前端 未结 3 760
遥遥无期
遥遥无期 2020-12-01 04:08

-Edit: Solution Found-
Figured it out after some heavy searching - one person (I literally mean one) said they instead used onPageLoad(); which worked perfectly for my p

3条回答
  •  盖世英雄少女心
    2020-12-01 04:19

    I've found what I think is a reasonable way to do this thanks to the previous answer and comments pointing me in the right direction.

    What I did is override onPageStarted and onPageFinished in a custom WebViewClient. The code goes something like this...

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
      if (pendingUrl == null) {
        pendingUrl = url;
      }
    }
    
    @Override
    public void onPageFinished(WebView view, String url) {
      if (!url.equals(pendingUrl)) {
        Log.d(TAG, "Detected HTTP redirect " + pendingUrl + "->" + url);
        pendingUrl = null;
      }
    }
    

    And of course along with the Log.d you would put any specific code you want to run upon detecting the redirect.

提交回复
热议问题