Android: Download File from URL with Progress Bar

In my previous tutorial, I have explained how to upload a file to the server in Android. In this tutorial, we will see how to download a file from a given URL and store the file in external storage.

1. Create a project named Download File from URL in Android Studio.

2. Add Internet and Write to External Directory permissions to AndroidManifest.xml:

3. We will be using Easy Permissions library for handling runtime permissions in Android M and above. So add the dependency to build.gradle file of the app module:

4. Add the string resources used in the project to strings.xml

5. In activity_main.xml, add an EditText of inputType textUri, used for the user to input file URL and add a download button.

6. Create a helper class with the name CheckForSDCard.java this has a static method isSDCardPresent which is used to check if SD card is present on the device or not.

7. Finally, add the following code in MainActivity.java. Here, when the user clicks on the download button, it checks whether there is permission to access the external storage. If the permission is present, it calls an Async Task to download the file with the user inputted URL. If the permission is not present, it asks for the same.

8. Now run the app on your Android device.

You can see the demonstration of the app in the below animation:

Download file from server demo

You can download the Source code and APK files from the below links:

Download Source CodeDownload APK

If you have any doubts, then we can discuss them in the comments section. If you have liked this tutorial, please do follow us on Twitter and Facebook.

Stay Connected

No spam guarantee.

Abhishek

Abhishek

Abhishek loves coding. His favorite is Android Development. Apart from coding he loves traveling and reading.
Abhishek

Leave a Reply

Your email address will not be published. Required fields are marked *