SoFunction
Updated on 2025-03-01

Solution to handle 302 redirects without jumping in Android WebView

Recently, the Webview loaded a third-party redirect with 302, but found that it did not redirect. Finally, the problem was found as follows:

 public boolean shouldOverrideUrlLoading(WebView view, String url) {
   (view, url);
   ........
   .........
   return true;
 }

I found the last returned true, so there will be no redirect jump. Just return fasle and you can redirect jump. If you need it in some cases, return true and process some urls by yourself, then you can make your own judgment.

Soreturn fasle andreturn true What's the difference?

Return result meaning
true It means that you handle it yourself and there is no need for system processing. For example, if it is true, the redirect will not jump
false It means that the developer will not handle it himself and leave it to the system for processing

Supplementary knowledge:Don't let WebView call the system's own browser

webView2= (WebView) findViewById(.webview2);
 
    (new WebViewClient( ){
      //OverrideUrlLoading method      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url){
        (url);
        return true;
      }
    });
 
    ("");

Rewrite setWebViewClient

The above solution to the processing of 302 redirection and not jumping in Android WebView is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.