2

I am developing an android application in which i have to download multiple sound files from a server. Each file has approximately 10MB size. For that i have used Download Manager to download multiple files from server. But when i downloading multiple files from server download process is being killed by android os after downloading 2 or 3 sound files. Because of download process requires more resources and another application on a device requires resources to run. I have googled to solve this problem but can't get any kind of solutions regarding my problem. If anybody has solution of this problem then please suggest me, Or is there any example or sample then also please suggest me.

Below are some code snippet,

Uri Download_Uri = Uri.parse(urls[idList.get(0)]);
    DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
    long download_id = downloadManager.enqueue(request
                .setAllowedNetworkTypes(
                  DownloadManager.Request.NETWORK_WIFI
                | DownloadManager.Request.NETWORK_MOBILE)
                .setAllowedOverRoaming(false)
                .setTitle("Downloading...")
                .setDescription(Songs[idList.get(0)])
                .setDestinationInExternalPublicDir(
                    Environment.DIRECTORY_DOWNLOADS,
                    Songs[idList.get(0)] + ".mp3"));

Upper sample is used to initiate download,

rav_kr
  • 434
  • 8
  • 16

1 Answers1

0

It there is a bug in download manager, as discussed here. Download manager will automatically re request files/tracks failed due to network connectivity problems. But it is failing to serve, when multiple and repetitive requests are made. It is storing data about failed or partially downloaded files in download manager application cache. whenever it is implicitly downloading again, it is using previous data, which is not accurate to make some range requests. That is why it is always failing give either range request failed or error can not resume after multiple or repetitive downloads.

Manual Solution

go to settings-> manage applications-> download manager (under all tab)-> clear data

After doing this you can observe success rate as very high.

In order clear download manager data through code you need vendor keys.

For more: DownloadManager.ACTION_DOWNLOAD_COMPLETE broadcast receiver receiving same download id more than once with different download statuses in Android

Community
  • 1
  • 1
Ganesh K
  • 2,623
  • 9
  • 51
  • 78