Download Image or file from Server in Phone Storage(Download manager)


Hey, friends in this blog I will tell you how you can download Image or a big file in Android Studio.
In fetching of an image, you can Fetch with volley Network Image library, Picasso, Glide.
the are popular API to fetch images from Server but if I want to Download an image from Server, there is way more Complex method in Picasso to Download file.
To simplify it Android have already Download Manager.
By the help of Download manager, you can download any image or big file
So it's the best way to download an image from Server.

Official Doc-ClickHere

Steps Todo-

1. First of all, Take the Internet and Storage permission By adding below lines in Manifest file in Android.

2. Now In activity_main.xml make a button In this button Click we will download Image from URL.

3. After Taking Permission For Internet and WRITE_EXTERNAL_STORAGE permission we have to take run time permission for WRITE_EXTERNAL_STORAGE. So you can write below code for run Time Permission.
4. Now if permission is Granted I will try to download Image from Url otherwise I will prompt alert to give write storage permission Like Below.
5. Now make DownloadFile fn and pass Url to it Like below.
6. Now your final MainActivity.java file looks Like below.
7.This type you can download any image or file from Server using URL with the help of
Download manager.
8. This is the DownloadManger function which is responsible for Download Image From Server-
                           Uri downloadUri = Uri.parse(uRl);
 DownloadManager.Request request = new DownloadManager.Request( downloadUri);

9. If you have any problem in this procedure you can Download Source Code from the below link.


                                   Download Code-ClickMe

Post a Comment

0 Comments