当前页面是重定向的,监听返回键调用webview.goback(),就一直加载当前页面
处理方式是,http开头的url,用super.shouldOverrideUrlLoading(view, request)
处理
非http开头的,用intent处理
private String currentUrl = "";
mWebview.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
currentUrl = url;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(loadUrl(view, url)){
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String url = String.valueOf(request.getUrl());
if(loadUrl(view, url)){
return true;
}
return super.shouldOverrideUrlLoading(view, request);
}
}
private boolean loadUrl(WebView view, String url){
LogUtil.LogE("ZLWebPlatformActivity shouldOverrideUrlLoading " + url);
if(url.startsWith("http")) {
return false;
}
try{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}catch (Exception e){
e.printStackTrace();
}
return true;
}
网友评论