如何在Android中通过webView下载文件

如何在Android中通过webView下载文件,android,Android,我想通过android中的webView下载一个文件。但是我不明白怎么做?webView的代码如下所示。您能建议我在webView中下载文件时可以做些什么吗 wv = (WebView) findViewById(R.id.mainwebview); WebSettings ws = wv.getSettings(); // ws.setBuiltInZoomControls(true); // wv.loadUrl("http://www.ebo

我想通过android中的webView下载一个文件。但是我不明白怎么做?webView的代码如下所示。您能建议我在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);
        }
    });
运行此代码后,我出现了如下错误,如图所示: 我认为这对你有帮助。用于在android的webview上下载文件

编辑:-

试试下面的代码

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

我无法理解该答案中提供的代码。你能把那个代码和我的代码结合起来吗?这将对我很有帮助………是的,我上传了这个文件。