dors dors - 1 year ago 80
Android Question

Best way to download a file in an Android app

I try to understand the pros and cons of different ways to download a file using an android app.

I found several ways:

  1. Managing the download on my own (see this code snippet)

  2. Using Android's DownloadManager

  3. Downloading a file using OKHttp as described in this post

Does anyone with experience in the subject can tell me reasons for choosing one way over the other?

Answer Source

Is the file a user file (meaning the user should have access to the file, e.g. a photo or document that is for him to have)?

  • If yes, use the downloadmanager. The Android framework will handle all the download, giving a proper user notification, be available on the Download app, etc.
  • If no, either on your own or via OkHttp will work, but OkHttp is a great library very well developed, stable, fast and will minimise your headaches during development. (did you know that starting in Lollipop, Android uses internally the OkHttp library? That's how good it is)