majidgolshadi / android-download-manager-pro Goto Github PK
View Code? Open in Web Editor NEWAndroid/Java download manager library help you to download files in parallel mechanism in some chunks.
License: MIT License
Android/Java download manager library help you to download files in parallel mechanism in some chunks.
License: MIT License
URL url = new URL(task.url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(1000);
connection.setReadTimeout(1000);
in AsyncWorker.class having above code throws socket time out exception
and download stops after few moments
whenever i made below changes in above code it works well sometimes and after sometime again facing same problem
URL url = new URL(task.url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(60000);
connection.setReadTimeout(60000);
Using MotoG3 for testing device android MarshMallow 6.0.1
Hello, I am kind of confused and also new to java, but usualy libraryz have some kind of tutorial like:
"download this jar and put it in the folder xxx"
Or
"Add dependencie xxxx to gradle"
But on this one I can t find anything and it s frustrating as I would like to use this library on my project.
Can someone please give me the steps to use it? Thank you
in run() method of AsyncWorker, you catch MalformedURLException and IOException. But since it is printing only in stackTrace, I don't have any way how to propagate those errors to UI to stop / restart download. Is there any way around ? Or it would be nice to have some exception callback.
Thanks
I`d used this lib,there are many bugs in it,
I found FileDownloader instead ,
is much better than this no sample one
Any good example how to implement this library ?
Hello,
do I need to worry about downloading states when I call dispose()?
I run the downloadManagerPro in the service. But the service can be stopped by the system. So in the onDestroy I want to pause all downloading files and then call dispose. But there is no listener for onPauseAllDownloads.
So my question is: Do I need to pause dowloads before dispose or can I omit the dispose function at all?
Thank you in advance.
I followed the example and gave full permissions and While i can download files using Volley and other methods, This library is actually stuck at OnDownloadStarted for some reason, this is all i get. Any idea how to fix this?
T.N,
File is on a direct URL
Android 7.1.1
Other download methods work
also my code is
DownloadManagerPro dm = new DownloadManagerPro(con);
dm.init(path,12,con);
int token = dm.addTask(name,url,12,path,true,true);
try {
dm.startDownload(token);
}catch (Exception e){
Log.w("download_manager","Error "+e.getMessage());
}
and
@OverRide
public void OnDownloadStarted(long taskId) {
Log.w("download_manager","Download Started "+taskId);
}
@Override
public void OnDownloadPaused(long taskId) {
Log.w("download_manager","Download paused "+taskId);
}
@Override
public void onDownloadProcess(long taskId, double percent, long downloadedLength) {
Log.w("download_manager","Download process, percent="+percent+" downloadedLength="+downloadedLength);
}
@Override
public void OnDownloadFinished(long taskId) {
Log.w("download_manager","Download finished "+taskId);
}
@Override
public void OnDownloadRebuildStart(long taskId) {
Log.w("download_manager","Download Rebuild Start "+taskId);
}
@Override
public void OnDownloadRebuildFinished(long taskId) {
Log.w("download_manager","Download Rebuild finished "+taskId);
}
@Override
public void OnDownloadCompleted(long taskId) {
Log.w("download_manager","Download Rebuild completed "+taskId);
}
@Override
public void connectionLost(long taskId) {
Log.w("download_manager","Download connection lost "+taskId);
}
and All i get is
download_manager: Download Started 2
System.err﹕ java.net.SocketTimeoutException
System.err﹕ at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491)
System.err﹕ at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
System.err﹕ at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
System.err﹕ at java.io.BufferedInputStream.read(BufferedInputStream.java:304)
System.err﹕ at libcore.net.http.FixedLengthInputStream.read(FixedLengthInputStream.java:45)
System.err﹕ at java.io.InputStream.read(InputStream.java:163)
System.err﹕ at com.golshadi.majid.core.chunkWorker.AsyncWorker.run(AsyncWorker.java:64)
for the first time downloaded properly...after then always getting this error...why?
I want to start a queue with 5 download tasks, what should I do from the start to the end?
I want to get the status of downloaded file while its downloading.For that I am using ReportStruct.But both report.getTotalSize() and report.toJsonObject().get("percent") is returning 0 even if i place report.toJsonObject().get("percent") inside onDownloadProcess.How can i get the percentage progress of downloaded video?
int taskToekn = dm.addTask(caption, url, false, false);
try {
dm.startDownload(taskToekn);
} catch (Exception e) {
e.printStackTrace();
}
ReportStructure report = dm.singleDownloadStatus(taskToekn);
Log.e("BHUV", "totalsize" + report.getTotalSize());
try {
Log.e("Bhuv", "percent" + report.toJsonObject().get("percent"));
} catch (JSONException e) {
e.printStackTrace();
}
Both Logs return 0 and 0.0
Getting this error while download large files, size larger than 20MB
ajmalrasi.com.rasi.hellod W/System.err: java.net.ProtocolException: unexpected end of stream ajmalrasi.com.rasi.hellod W/System.err: at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:421) ajmalrasi.com.rasi.hellod W/System.err: at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:371) ajmalrasi.com.rasi.hellod W/System.err: at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) ajmalrasi.com.rasi.hellod W/System.err: at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) ajmalrasi.com.rasi.hellod W/System.err: at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ajmalrasi.com.rasi.hellod W/System.err: at java.io.FilterInputStream.read(FilterInputStream.java:107) ajmalrasi.com.rasi.hellod W/System.err: at com.golshadi.majid.core.chunkWorker.AsyncWorker.run(AsyncWorker.java:94)
any idea how to solve this issue, looked up this error on google but couldn't a find solution.
hi. can i insert headers to each download request?
ReportStructure report = dm.singleDownloadStatus(taskToekn);
The all atributes are private in ReportStructure.
Hello sir,
I am new to android , can you please provide sample application how to use this library
it help me to learning.
Thanks
I have set up a longer link time, but there is still a problem
[CDS]read byte is 0
java.net.SocketTimeoutException
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:497)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:42)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:242)
at com.android.okio.Okio$2.read(Okio.java:113)
at com.android.okio.RealBufferedSource.read(RealBufferedSource.java:48)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:446)
at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
at java.io.InputStream.read(InputStream.java:162)
at com.golshadi.majid.core.chunkWorker.AsyncWorker.run(AsyncWorker.java:64)
Thank you for opening this good module
But I guess that this module only support overwrite or not.
I can add function "download from where it stopped", if you want
I change value type 'boolean overwrite' to 'int downloadMode' in addTask() method.
int downloadMode can be tree types
How to resume the paused download task ?
Hello,
when I try to download some video files, it does nothing. OnDownloadStarted is called, but nothing else.
The file that I try to download is: http://www.sample-videos.com/video/mp4/360/big_buck_bunny_360p_2mb.mp4
This is what I get from downloadTasksInSameState:
{
"token":"39",
"name":"save_name_15",
"state":3,
"resumable":true,
"fileSize":-1,
"url":"http:\/\/www.sample-videos.com\/video\/mp4\/360\/big_buck_bunny_360p_2mb.mp4",
"type":"mp4",
"chunks":1,
"percent":0,
"downloadLength":0,
"saveAddress":"\/storage\/emulated\/0\/downloadManager\/save_name_15.mp4",
"priority":true
}
Thank you for your help.
Daniel
Can someone please give me the steps to use it? Thank you
Is there any listener or state that triggered when download failed?
some time i got this error
Exception java.lang.NullPointerException:
com.golshadi.majid.core.chunkWorker.Rebuilder.run (Rebuilder.java) any body have idea how to fix this
Such as the title!
java.net.protocolException: unexpected end of stream
AsyncWorker.run (AsyncWorker.java:65)
percent greater than 100%
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/package_name/databases/com.doitflash.air.extension.downloadManagerPro
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1626)
at com.golshadi.majid.database.ChunksDataSource.delete(ChunksDataSource.java:75)
at com.golshadi.majid.core.chunkWorker.Moderator.reBuildIsDone(Moderator.java:193)
at com.golshadi.majid.core.chunkWorker.Rebuilder.run(Rebuilder.java:69)
it happening only for low memory device...any idea...
//check whether a thread is interruptted or not by this is not a good choice.
Thread#isInterrupted()
i invoke downloader.puaseDownload(int token);
and it finally interrupts the AsyncWorker,but in AsyncWorker this.isInterrupted()
is false.
so observer.rebuild(chunk);
is invoked .
that is to say ,invoke downloader.puaseDownload(int token);
and observer.rebuild(chunk);
will be invoked too.
so, the task's
state is wrong.
//my solution
volatile boolean interrupt = false;
@Override
public void interrupt() {
super.interrupt();
interrupt = true;
}
//update #run
```java
while (!interrupt &&
(len = remoteFileIn.read(buffer)) > 0) {
watchDog.reset();
chunkFile.write(buffer, 0, len);
process(len);
}
if (!interrupt) {
observer.rebuild(chunk);
}
how to resume a paused task? And how to "resume broken downloads"?
Hi,
Just tried this library and I am not able to download files. I tried downloading from these sites apkleecher.com and www.mp3juices.cc.
It says Download started but the download is never completed and I see small files created in external storage.
Can you please verify it if it is an issue with the library or with the sites?
D/BBK_MainActivity: [MainActivity.java_118_onDownloadProcess] taskId: 1 percent:25.49293327331543 downloadedLength:2328545
D/BBK_MainActivity: [MainActivity.java_167_connectionLost] taskId: 1
Where can download library using gradle
Plz look at line 59~!
Initialize DownloadManagerPro
String saveFielPath
: folder address that you want to save your completed download task in it.
I think that you need to modify the "saveFielPath" to "saveFilePath".
So I think it should be modified in the following sentence.
String saveFilePath
: folder address that you want to save your completed download task in it.
Thank you :D ~
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.FileInputStream.read(byte[])' on a null object reference
at downloadmanager.core.chunkWorker.Rebuilder.run(Rebuilder.java:53)
hi , thx for this great library but i am facing issue , in lolipop 5.0 ondownloadFinished Called Directly after connectionlost , but on other apis it works fine even on 5.1 , this issue appear only in 5.0
i noticed that an error raised
07-31 16:50:06.941 1670-1804/com.filmov.itech.movies E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-229
Process: com.filmov.itech.movies, PID: 1670
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.FileInputStream.read(byte[])' on a null object reference
at tools.majid.core.chunkWorker.Rebuilder.run(Rebuilder.java:52)
Please, help me to understandm how can i know in which state my task : pause, downlaoded or something else. After i write ReportStructure report = dm.singleDownloadStatus(taskToken); how can i get information from that ? Thank you
Also I didn`t find the code segment for checking integrity
because of this library has more bug and cause of getting bad feed back on crashing our application i had to remove this library on our projects
با سلام و عرض خسته نباشید
من میخواستم از این کتابخونه استفاده کنم اما قبلش نیازه این سوال رو بپرسم
مثلا من یک فایل رو دادم دانلود کنه و اون فایل تا نصفه دانلود شده ، حالا من برنامه رو میبندم و میخوام وقتی کاربر بعدا دوباره وارد برنامه شد و ادامه دانلود رو زد ، دادمه فایل دانلود بشه ایا همچین چیزی توی این کتابخونه هست؟
با تشکر
hi new issue , i tried in the past days to download video files with 12 chunks but after download finished , i tried to play the video i noticed that the video became corrupted in some places , i tried the same file with 1 chunk , and i tried to play it after finishing download , the video played correctly without any issue , i think that there is issue in regrouping algorithm of chunks after finishing , i hope to fix this issues soon because when i put the chunk to 1 the download speed became very slow
hello
can i get progress of download queue?
for example you forgot to close it in TaskDataSource
in the method getUnCompletedTasks
You are also not persistent in the way you close your cursors. Sometimes you check if the cursor object is null
, and sometimes you do not.
Is there also a reason why the connection to the database is never closed? I see an unused method called close() in TaskDataSource. I do not properly understand the source code just yet to understand when I should call this method
I'm trying to pause current download on onStop
by this code:
@Override
protected void onStop() {
super.onStop();
Alachiq.getDefaultInstance().pauseDownload(Alachiq.getDefaultInstance().getCurrentDownloadingTaskId());
EventBus.getDefault().unregister(this);
}
public int getCurrentTask(){
int thisTask = 0;
String query = "SELECT * FROM " + TABLES.TASKS
+ " WHERE " + TASKS.COLUMN_STATE + "==" + SqlString.Int(TaskStates.DOWNLOADING);
...
}
but i get an error on this line of code
.core.chunkWorker.ConnectionWatchDog.run(ConnectionWatchDog.java:56)
Hi~Can you explain this difference between those two interfaces?
Hi
I am downloading 2 files by below method.
dm.startQueueDownload(1, QueueSort.oldestFirst);
Then, I am disconnecting internet and trying to start queue again but it is throwing
com.golshadi.majid.report.exceptions.QueueDownloadInProgressException: queue download is already in progress
at com.golshadi.majid.core.DownloadManagerPro.startQueueDownload(DownloadManagerPro.java:182)
Please help me to resume queue again..
Thanks
please @majidgolshadi supply a basic example of how to use your library
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.