My Problem is that when I hit the pdf link in the webview, the browser opens for a short moment (I guess to download the linked file), the pdf file starts to download and the app returns back to the webview. Is there a way to stop the browser window opening to start the download?
I have used WebViewClient to shouldOverrideUrlLoading so that clicked urls are kept in the webview:
private class LinkWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
And I have a download listener so I can download files (for my needs these are pdf's):
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});