Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView download opens browser window for a short moment before returning to WebView

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);

        }
    });
like image 387
qubz Avatar asked Dec 21 '10 06:12

qubz


1 Answers

Add the MIME type to your Intent you use with startActivity() in your download listener.

like image 101
CommonsWare Avatar answered Sep 18 '22 06:09

CommonsWare