Multiple File Download Manager In Listview +progress/pause/resume Android
Solution 1:
finally after about 1years(:D) this is one of best solutions :
using this library by add to project with library ,
or with Android Studio dependencies :
dependencies {
compile'com.mani:ThinDownloadManager:1.3.0'
}
it's one of best and fast (any) file Download library , Too is so simple to use and customize.
for example in my question(in 1 year ago) that i wanted to have Multiple-File-Download
, at ease can specify thread pool size by :
ThinDownloadManagerdownloadManager=newThinDownloadManager(DOWNLOAD_THREAD_POOL_SIZE);
//DOWNLOAD_THREAD_POOL_SIZE = number of threads.
goodLuck!.
Edit for answer to @Bhuvi , (set destination downloaded file)
Define file destination :
StringfileName="file name"; Fileroot= android.os.Environment.getExternalStorageDirectory(); Filedir=newFile(root.getAbsolutePath() +`subfolder name`); if (dir.exists() == false) { dir.mkdirs(); } finalUridestinationUri= Uri.parse(dir + fileName);
then
setDestinationURI
(your path) forThinDownloadManager
downloadRequest = newDownloadRequest(downloadUri)setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH)
Edit @farhad.kargaran answer - 2017/12/06
as i saw ThinDownloadManager repository , last version is 1.3.0
but According to @farhad.kargaran answer there are version 1.4.0
too , i have not tested new version's features ,but you can also test the new version according to @farhad.kargaran's answer.
Solution 2:
Assuming you don't have a custom adapter and you're using something similar to AndroidListClient.java supplied in that tutorial (this assumption is based on you're reference to the article for the code sample).
So, instead of:
ArrayAdapter<String> adapter = newArrayAdapter<String>(this, R.layout.list, initialList);
this.setListAdapter(adapter);
create your own custom adapter extending from Base Adapter. (If you already have a custom adapter please post the code).
In your adapter, use viewHolder pattern and don't inflate your list each time item is added.
You can find more about custom adapter here: http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown_example
Solution 3:
Had the same problem. Here is how i solved it (i no longer have the code so we'll have to make due): (I had a database so it was relatively simple to manage the downloads. gave them the item id)
- In your AsyncTask broadcast a intent with the item number and the procentage completed (onProgressUpdate)
- Implement a LocalBoradcastReciever in your activity and update the ListView with the new values.
I literally have no idea how to pause/resume the download.
I used a static variable to cancel the download (ex cancel no 7, when reading the bytes for the server if(download == 7) return).
Cheers!
Solution 4:
use
dependencies {
compile'com.mani:ThinDownloadManager:1.4.0'
}
but in its github it says the last vesion is 1.3.0 but in fact pause and resume feature is in 1.4.0 version and github readMe is not up to date, pay attention to setDownloadResumable() in the following code
DownloadRequestdownloadRequest=newDownloadRequest(downloadUri)
.addCustomHeader("Auth-Token", "YourTokenApiKey")
.setRetryPolicy(newDefaultRetryPolicy())
.setDownloadResumable(true)
and for multipart you should do it in initializing download manager as the following code:
int availableProcessors = getRuntime().availableProcessors();
downloadManager = newThinDownloadManager(availableProcessors);
Post a Comment for "Multiple File Download Manager In Listview +progress/pause/resume Android"