Solution of Redirection Without Jump in Processing 302 in Android WebView
- 2021-11-30 01:24:23
- OfStack
In the most recent project, Webview loaded the third party's redirection with 302, but found that it did not jump again. Finally, the problems are found as follows:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
........
.........
return true ;
}
Found the last returned true, so it will not redirect the jump, as long as you return fasle can redirect the jump, if you need to return true to handle some url yourself, then you can make your own judgment.
Then
return fasle
And
return true
What's the difference?
返回结果 | 含义 |
---|---|
true | 表示自己处理,不需要系统处理,比如如果是true,重定向就不会跳转 |
false | 表示开发者自己不处理,交给系统处理 |
Additional knowledge: Do not let WebView call the system's own browser
webView2= (WebView) findViewById(R.id.webview2);
webView2.setWebViewClient(new WebViewClient( ){
// Covering shouldOverrideUrlLoading Method
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
webView2.loadUrl("http://www.baidu.com");
Rewrite setWebViewClient