0

我有几种文件格式,如 JPG、PDF、ZIP,我想将这些文件下载到我的应用程序中。PDF 和 ZIP 文件下载良好,但我无法下载 JPG 文件。知道如何下载JPG文件吗?

HTML 页面在这里http://www.sotkora.com/xy/ex_download.html

  public class DownloadingExample extends Activity {

    WebView webView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_downloading_example);


        this.webView=(WebView) this.findViewById(R.id.webView_IF);
        this.webView.getSettings().setSupportZoom(false);
        this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
        this.webView.loadUrl("http://sotkora.com/xy/ex_download.html");
        this.webView.setWebViewClient(new WebViewClientDemo());
        this.webView.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent,
                            String contentDisposition, String mimetype,
                            long contentLength) {

                                          Uri uri = Uri.parse(url);
           Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                    startActivity(intent);
            }
    });

    }
  private class WebViewClientDemo extends WebViewClient {
    @Override

    public boolean shouldOverrideUrlLoading(WebView view, String url) {
     view.loadUrl(url);
      return true;
     }

  }

HTML 代码:

<div><a href="http://www.sotkora.com/xy/images/rose.jpg" download="JPGPhoto">Download JPG Photo</a></div><br/>
        <div><a href="http://www.sotkora.com/xy/files/load_test.pdf" download="pdf_test">Download PDF File</a></div><br/>
        <div><a href="http://www.sotkora.com/xy/files/load_test.zip" download="ZIP_test">Download ZIP File</a></div><br/>
4

1 回答 1

0

如果您使用正确的标题进行下载,您应该能够执行以下操作...(您需要实现自己的下载过程)

mWebView.setDownloadListener(new DownloadListener() {
    public void onDownloadStart(String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {
        // Download via android code
    }
});
于 2013-08-13T21:24:25.620 回答