Search code examples
androidandroid-download-manager

Downloading files in a queue using download manager in android?


I am downloading multiple file same time with download manager. but my problem is download manager start download all files with same time i need to start download file one by one in queue means first item download first than all one by one.

DownloadManager.Java

if(downloaddata.size()>0){              
   for(int i=0;i<downloaddata.size();i++){
        downloadFiles(downloaddata.get(i).getFile_id(),downloaddata.get(i).getFile_url(),"OTHER");
   }
}   


 public void downloadFiles(String myid,String myurl,String type){
        createFolder();
        String fileName = URLUtil.guessFileName(myurl, null, null);
        Uri uri=Uri.parse(myurl);
        request=new DownloadManager.Request(uri);
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
        request.setTitle(myid);
        request.setMimeType(type);
        request.setDestinationInExternalPublicDir("/peakmedia",fileName);            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
        downloadReference=downloadManager.enqueue(request);
        downloadlist.add(downloadReference);

    }

Solution

  • DownloadManager broadcasts ACTION_DOWNLOAD_COMPLETE, so you can just request the next file to download when the BroadcastReceiver receives success for previous file.