Android webview shouldOverrideUrlLoading方法未被调用onclick具有pdf文件的链接
代码:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.endsWith(".pdf")){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
return true;
} else{
view.loadUrl(url);
}
return true;
}
答案 0 :(得分:0)
试试这个
private class WebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// check here the url
if (url.endsWith(".pdf")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
} else {
super.onPageStarted(view, url, favicon);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
}