1

Possible Duplicate:
Download File inside WebView

I have a WebView on my screen:

webDownloadTicket = (WebView) findViewById(R.id.webViewToDownload);
webDownloadTicket.getSettings().setJavaScriptEnabled(true);
webDownloadTicket.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return false;
    }
});
      // and load url
webDownloadTicket.loadUrl("xxx.com/TicketWEB/download.jsp");
      // setup for download listener
webDownloadTicket.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);

    }
});

I was testing with browser, going to this URL and then press the download button, it will download a JSON file.

But when I test on my Android app with that code, it can load the web page but can not download anything when I press download button.

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
Le Phong Vu
  • 156
  • 2
  • 12

1 Answers1

1

The most common answer for not being able to access network from an app is a missing permission-declaration in AndroidManifest.xml. Check the file for this line and add it if it's not there:

<uses-permission android:name="android.permission.INTERNET" />
Andreas Hage
  • 101
  • 3
  • I did it. becuz I can go to link www.xxx.com/TicketWEB/download.jsp In this page, have a button, and when I press it, download a file. But i can not do in my app. when i test with browser on my phone, it ok. – Le Phong Vu Nov 26 '12 at 07:05