Skip to content

Commit e782559

Browse files
authored
Merge pull request #390 from Oklahomawhore/master
Add automatic resume for unexpectedly killed works.
2 parents ba7f05f + a243a94 commit e782559

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

android/src/main/java/vn/hunghd/flutterdownloader/DownloadWorker.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ public Result doWork() {
189189
updateNotification(context, filename == null ? url : filename, DownloadStatus.RUNNING, task.progress, null, false);
190190
taskDao.updateTask(getId().toString(), DownloadStatus.RUNNING, task.progress);
191191

192+
//automatic resume for partial files. (if the workmanager unexpectedly quited in background)
193+
String saveFilePath = savedDir + File.separator + filename;
194+
File partialFile = new File(saveFilePath);
195+
if (partialFile.exists()) {
196+
isResume = true;
197+
log("exists file for "+ filename + "automatic resuming...");
198+
}
199+
192200
try {
193201
downloadFile(context, url, savedDir, filename, headers, isResume);
194202
cleanUp();

0 commit comments

Comments
 (0)