0

I have an arcive of several files format like JPG, PDF, ZIP and I want to download the files into my app. The PDF and ZIP files are being downloaded well but I can not download the JPG files. Any idea how can I download the JPG files as well?

HTML page here 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 code:

<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/>
Asim Roy
  • 9,915
  • 4
  • 28
  • 40
  • What does it do when you click on a link inside the webview? – JRomero Aug 13 '13 at 20:42
  • @J.Romero It just again shows the image which I want to download – Asim Roy Aug 13 '13 at 20:47
  • It seems that only the content which cannot be handled by the system is downloaded instead. Check this post: http://stackoverflow.com/questions/15746077/downloadlistener-doesnt-download-images – Marcin S. Aug 13 '13 at 21:20
  • @MarcinS. BOSS, Can you please help me how can I register the interface so it should be downloaded? – Asim Roy Aug 13 '13 at 21:38

1 Answers1

0

If you are using proper headers for downloading you should be able to do the following... (You will need to implement you own download process)

mWebView.setDownloadListener(new DownloadListener() {
    public void onDownloadStart(String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {
        // Download via android code
    }
});
JRomero
  • 4,878
  • 1
  • 27
  • 49