Multiple file download managers in list view + progress / pause / resume android

I need to create a dynamic download manager for my application in this form:

  • adding a new link to the current list
  • may pause and resume downloading.
  • remove full downloads from user list

    like this pic:

I first use this site code to download streams.

then I create my own list view, which every time the user clicks the "Download" button, a download link will be added.

But I have two problems:

  • after adding a new link to the list, the whole list will be new!
  • previous incomplete downloads will be new, as the list will be new!

Now the question is: how can I create a dynamic download manager for my application that can add a new link to the list with the ability to pause / resume and remove the downloaded item from the user list?


Edit - Add Custom-Listview

my custom list-view in this link: https://github.com/saeid-pm/Custom-Listview

+6
source share
4 answers

finally, after about 1 year (: D) this is one of the best solutions:

using this library , add to the library project,

or with Android Studio dependencies:

dependencies { compile 'com.mani:ThinDownloadManager:1.3.0' } 

This is one of the best and fastest (any) files. Download the library, Too is so easy to use and configure.

for example, in my question (1 year ago) that i wanted to have Multiple-File-Download , it can indicate the size of the thread pool to:

 ThinDownloadManager downloadManager = new ThinDownloadManager(DOWNLOAD_THREAD_POOL_SIZE); //DOWNLOAD_THREAD_POOL_SIZE = number of threads. 

GOODLUCK !.


Edit to reply to @Bhuvi (install downloaded destination file)

  • Determine the purpose of the file:

      String fileName ="file name"; File root = android.os.Environment.getExternalStorageDirectory(); File dir = new File(root.getAbsolutePath() +`subfolder name`); if (dir.exists() == false) { dir.mkdirs(); } final Uri destinationUri = Uri.parse(dir + fileName); 
  • then setDestinationURI (your path) for ThinDownloadManager

     downloadRequest = new DownloadRequest(downloadUri)setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH) 

Edit @ farhad.kargaran answer - 2017/12/06

as I saw the ThinDownloadManager repository, the latest version is 1.3.0 , but according to @ farhad.kargaran the answer is version 1.4.0 too, I did not test the new version functions, but you can also test the new version according to the answer of @ farhad.kargaran.

+6
source

Assuming you don’t have a user adapter and you are using something similar to AndroidListClient.java provided in this tutorial (this assumption is based on the fact that you are linking to an article for sample code).

So, instead of:

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list, initialList); this.setListAdapter(adapter); 

create your own adapter, extending from the base adapter. (If you already have a custom adapter, send the code).

In your adapter, use the viewHolder template and do not inflate your list every time an item is added.

You can learn more about the custom adapter here: http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown_example

0
source

There was the same problem. This is how I solved it (I don’t have any code anymore, so we will have to do it): (I had a database, so it was quite simple to manage the downloads, giving them the item ID)

  • Your AsyncTask translates an intent with a position number and completion of procentage (onProgressUpdate)
  • Integrate LocalBoradcastReciever into your operations and update ListView with new values.

I do not know how to pause / resume the download.

I used a static variable to cancel the download (ex cancel no 7, when reading bytes for the if server (download == 7) return).

Hooray!

0
source

use

 dependencies { compile 'com.mani:ThinDownloadManager:1.4.0' } 

but in github he says that the last vesion is 1.3.0, but in fact the pause and resume function is in the 1.4.0 version and github readMe is not updated, pay attention to setDownloadResumable () in the following code

 DownloadRequest downloadRequest = new DownloadRequest(downloadUri) .addCustomHeader("Auth-Token", "YourTokenApiKey") .setRetryPolicy(new DefaultRetryPolicy()) .setDownloadResumable(true) 

and for multipart, you should do this when initializing the boot manager as the following code:

 int availableProcessors = getRuntime().availableProcessors(); downloadManager = new ThinDownloadManager(availableProcessors); 
0
source

Source: https://habr.com/ru/post/969459/


All Articles