2

I need download multiple files in one time (About 100 files)

It does not matter whether the download is synchronized

And the important thing is that all files be downloaded.

My code for getting urls and file names:

for (int i = 0; i < AssetData.size(); i++){
        String item = AssetData.get(i).toString();
        String name[] = item.split("/");
        String Url = setting.Main_Domain+"/"+item;// Url for downloading
        String fname =name[name.length-1] ;// File name like: test.txt
        File file2 =  new File(getFilesDir(),item.replace(fname,"")); // Parent File like: data/user/0/com.test.app/data/
        if(!file2.exists()){file2.mkdir();}

    }

The size of the files is small and all together is about 3 megabytes.

meti
  • 468
  • 1
  • 5
  • 27
AhmadReza
  • 421
  • 6
  • 20

2 Answers2

1

You can implement your code with using this library. You can download multiple files concurrent or you can start next download after one is completed.

https://github.com/MindorksOpenSource/PRDownloader

This is how your code will look

int downloadId = PRDownloader.download(url, dirPath, fileName)
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {

                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {

                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {

                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {

                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {

                            }

                            @Override
                            public void onError(Error error) {

                            }
                        });

Isn't this simple. :)

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • Hi, actually i am using PRDownloader library for downloading images. It simple only but unable to handle when multiple images download process complete or not. onDownloadComplete callback called once while first image get started to download. Rest of the images are being download in background. How to find that all the files/images are downloaded – user1784588 Apr 24 '20 at 11:31
0

This seems to me ion is a pretty elegant solution for you. It's easy to use and has many futures like connection pooling and reuse via HTTP Connection...

ucMedia
  • 4,105
  • 4
  • 38
  • 46