Android webview shouldOverrideUrlLoading method is not called onclick of a link which have pdf file
Code :
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;
}
Try This
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.