0

I have some question about download multiple file using service in android. From google search, all are recommended intent service but in my case I have list of file in list view, if user select any file it will download with notification progress, If user press back button from activity service need to run background, User can select multiple file, in each file have individual notification bar for progress

My question is

  1. If i choose intent service how can i pass File Url dynamically when user select the file, If i call start service with intent for each url it will not download parallel

  2. If i choose service and bind it, from document bind service not help for long running

  3. which method is best to achieve and how to i pass dynamic url into service and update the download url list

Thanks

Manikandan
  • 844
  • 15
  • 31

1 Answers1

0

Use the Android Download Manager.

The download manager is a system service that handles long-running HTTP downloads. Clients may request that a URI be downloaded to a particular destination file. The download manager will conduct the download in the background, taking care of HTTP interactions and retrying downloads after failures or across connectivity changes and system reboots.

In your Activity, where you defined your listview:

     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {

            String urlOfFileToDownload = (String) parent.getItemAtPosition(position);
            // Object item = parent.getItemAtPosition(position);

            DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            Uri uri = Uri.parse(urlOfFileToDownload);
            DownloadManager.Request request = new DownloadManager.Request(uri);
            Long reference = downloadmanager.enqueue(request);
        }
    });
Clive Seebregts
  • 2,004
  • 14
  • 18