osimer pothe
osimer pothe

Reputation: 2897

How to download a fileby webView in Android

I want to download a file by webView in android . But cant understand how to do that ? The code for webView is as follows . Can you please suggest me what can I do for downloading a file in webView ?

 wv = (WebView) findViewById(R.id.mainwebview);
        WebSettings ws = wv.getSettings();
     //   ws.setBuiltInZoomControls(true);
    //     wv.loadUrl("http://www.ebooksdownloadfree.com/");
        wv.getSettings().setJavaScriptEnabled(true);


        this.wv.getSettings().setSupportZoom(false);
        this.wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        this.wv.loadUrl("http://www.ziddu.com/download/20520057/MPTOH.pdf.html");
     wv.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent,
                String contentDisposition, String mimetype,
                long contentLength) {
          Intent i = new Intent(Intent.ACTION_VIEW);
          i.setData(Uri.parse(url));
          startActivity(i);
        }
    });

After running this code I got the following error as described in picture : enter image description here

Upvotes: 3

Views: 1866

Answers (1)

Hardik Joshi
Hardik Joshi

Reputation: 9507

I think This is helpful for you. FOr download Files on webview in android.

EDIT :-

Try following code.

mWebView.setDownloadListener(new DownloadListener() {
    public void onDownloadStart(String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {
      Intent i = new Intent(Intent.ACTION_VIEW);
      i.setData(Uri.parse(url));
      startActivity(i);
    }
});

Upvotes: 1

Related Questions