Pregunta

I am trying to use a ContentProvider to download a single, huge zip file to the internal storage using the DownloadManager as mentioned here (see option 2):

Create a ContentProvider which DownloadManager can write to and give it a URI that corresponds to this ContentProvider.

Can someone provide me with an example on how to achieve that? Is this what I'm trying to achieve?

Or is it a totally bad idea to do it this way?

¿Fue útil?

Solución

The answer you posted mentions a couple of scenarios:

  1. Where you want this file to be downloaded, if you use Download Manager certainly it will be treated as public download with other app can have access it.
  2. If you want it to be application context specific internal storage then, download it via any possible method, as the poster suggested use ContentProvider.

Now to add further, no matter what method you choose, code for downloading data would remain same. Perhaps I would suggest a more suitable solution, as ContentProvider are generally related for dealing with databases so drop that, instead

  1. Create a service, this will run in background
  2. Through this service spawn a thread for downloading data, this is very important no matter which method you use but if you try to hook any long network operation over main thread, android will close you app stating Network on main thread or ANR
  3. Upon completion of downloading you can stop your service, and do whatever you want from there.

Brilliant code for downloading file below along with usage of power manger etc. can be found here:

Download a file with Android, and showing the progress in a ProgressDialog

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top