Frank LaRosa
Frank LaRosa

Reputation: 3623

Android: download file programatically using the browser

My app has a string containing the URL to a file, typically something like a Word document or a PDF file. I want to give the user a way to download the file the same way they would if they had clicked on a link in the browser (letting the browser store it in the default location, etc).

At the moment I am doing this by launching an ACTION_VIEW intent. It works in most cases, but there are several problems with it. Often the browser window tries to display a message which for some reason immediately disappears and can't be read. Sometimes the download fails and I can't detect that. If it does succeed, all the user really sees is a small icon in the top status bar that they have to know to look for.

Is there a better way to do this? Some way to start a dedicated DOWNLOAD action instead of invoking the whole browser?

Could I download the file myself in my own code and then somehow cause it to end up in the same place as if the browser had downloaded it?

Thanks.

Upvotes: 1

Views: 1311

Answers (1)

jakebasile
jakebasile

Reputation: 8132

You can download it with your own code, and place it in the \Download folder on the SD card. Alternatively, you could use the DownloadManager available on API 9 and above.

Upvotes: 2

Related Questions