Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 974
dors Avatar asked Feb 02 '15 16:02

dors


People also ask

How do I download a file from an app?

Android phone or tabletTap and hold your finger on the file's download link until a menu of options appears, then release your finger. Tap the Download link or Download image option in the menu. If necessary, tap the Download option again, which may be required for some files to complete the download.

How do I download files on Android?

Go to the webpage where you want to download a file. Touch and hold what you want to download, then tap Download link or Download image. To see all the files you've downloaded to your device, open the Downloads app. Learn more about managing downloaded files.


1 Answers

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)
like image 50
Budius Avatar answered Oct 26 '22 16:10

Budius