3

I'm currently using a DownloadManager to download a ~20mb CSV to external storage through my app which requires the Write_External permission. I'd like to be able to download this CSV to my app's internal storage (so I don't have to require that permission and the guarantee that internal storage is always available) however a DownloadManager cannot do this/access my app's storage.

I know I can use an AsyncTask or a Download Service to do this stuff, but I like the way DownloadManager behaves in the sense that:

  • a download is automatically launched when the user regains an internet connection after starting one offline
  • it automatically handles pausing, resuming and retrying of downloads

Can I achieve this through an AsyncTask, Service or even a third party lib?

Adam Short
  • 498
  • 7
  • 28
  • "however a DownloadManager cannot do this/access my app's storage" -- it might with `FileProvider`, though I have not yet tried this. – CommonsWare Sep 04 '16 at 21:28
  • @CommonsWare according to a comment [here](http://stackoverflow.com/a/6495065/1860436) FileProvider's won't work: "As DownloadManager uses file:// scheme to access the file and FileProvider will give you URI wil scheme as content://" – Adam Short Sep 04 '16 at 21:31
  • 1
    Well, frak. I [filed a feature request](http://code.google.com/p/android/issues/detail?id=221670) to get this addressed. For a 20MB download, don't use `AsyncTask`, as the download might take quite some time. An `IntentService` would be a good choice while you are actively downloading. However, I am not certain if there are any HTTP client libraries that make pause/resume/retry very easy. Connectivity management is probably best handled via `JobScheduler`. – CommonsWare Sep 04 '16 at 21:49
  • I would rather let DownloadManager do the job, and then move the file to where you need it. – Rediska Sep 04 '16 at 22:29
  • @Rediska but wouldn't that still require the write permission? – Adam Short Sep 05 '16 at 05:59

0 Answers0