Comments (8)
Seems like there is a bug. I am looking into it
from fetch.
@RealAction Can you try this work around and let me know if it works for you? I am still looking into this issue.
Work Around:
DownloadInfo toDownload= mListDownloadInfo.get(holder.getAdapterPosition());
final Request request = new Request(toDownload.getUrl()
, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
,toDownload.getFileName());
final RequestInfo requestInfo = mFetchDownloader.get(request);
if(requestInfo != null && requestInfo.getError() == Fetch.ERROR_FILE_NOT_FOUND) {
Log.e("aaaa", "aaaa:"+requestInfo.getStatus());
Log.e("aaaa", "aaaa:"+requestInfo.getError());
mFetchDownloader.addFetchListener(new FetchListener() {
@Override
public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {
if(id == requestInfo.getId() && status == Fetch.STATUS_REMOVED) {
mFetchDownloader.enqueue(request);
mFetchDownloader.removeFetchListener(this);
}
}
});
mFetchDownloader.remove(requestInfo.getId());
}else {
toDownload.setDownloadId(mFetchDownloader.enqueue(request));
}
from fetch.
@RealAction - Not sure if I am understanding correctly, but if you want to re-download the same file at the same Location, just do a fetch.retry(old_download_id). I am doing the same and it seems to work. Although having the file removed from Fetch DB easily is desirable, this workaround seems to work for me in both the cases.
from fetch.
the code you post above fix half of issues, that make me confuse. Let me explain in 2 script:
NOTICE:
- in both 2 script Fetch will release then re-instance before user download
- i put 2 line "aaaa" log outsize of if block
Script 1 (success):
- Download the file
- User manually kill app completely (by click phone's menu button then slide to kill app)
- Delete the downloaded file
- User open app again then download
- Result: work perfect (download again success)
Script 2 (not success):
- Download the file
- User kill app (by click back button until app close)
- Delete the downloaded file
- User open app again then download
- Result:
05-23 21:52:44.679 14855-14855/com.devoflife.app.testdownload E/aaaa: aaaa:903 //status
05-23 21:52:44.679 14855-14855/com.devoflife.app.testdownload E/aaaa: aaaa:-1 //error
05-23 21:52:44.680 14855-14855/com.devoflife.app.testdownload W/System.err: com.tonyodev.fetch.exception.EnqueueException: DatabaseHelper already containsFilePath a request with the filePath:/storage/emulated/0/Download/pic_mountain.jpg
from fetch.
@RealAction The FetchService automatically removes the entry for a request if the file is moved or deleted. Can you provide me a sample app or log?
from fetch.
@RealAction disregard my previous answer. The following is how Fetch handles downloaded files that have been removed.
Every time the FetchService starts, its verifies the database by checking that the downloaded files still exist. If a file was deleted or cannot be accessed, the service sets the request status to Fetch.STATUS_ERROR
with an error value of Fetch.ERROR_FILE_NOT_FOUND
.
What you can do is query fetch for the request and check its status. If the status is invalid, remove the request and enqueue again. Example:
final Request request = new Request("url","dirPath","fileName");
final RequestInfo requestInfo = fetch.get(request);
if(requestInfo != null && requestInfo.getStatus() == Fetch.STATUS_ERROR
&& requestInfo.getError() == Fetch.ERROR_FILE_NOT_FOUND) {
//Listen for when the request has be removed
fetch.addFetchListener(new FetchListener() {
@Override
public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {
if(id == requestInfo.getId() && status == Fetch.STATUS_REMOVED) {
//Enqueue request
long downloadId = fetch.enqueue(request);
//Save downloadId....
fetch.removeFetchListener(this);
}
}
});
fetch.remove(requestInfo.getId());
}else {
long downloadId = fetch.enqueue(request); //Save downloadId....
}
Let me know if this works how you except.
from fetch.
@tonyofrancis
i made simple example so you can see issue: https://github.com/DevOfLife/TestDownload5
step:
- click into folder icon to download the sample image (located on Downloads folder of sd card)
- close the app
- Delete the downloaded image
- then re-open the app
- click into folder icon again to download
result log:
05-19 22:28:34.359 8084-8084/com.devoflife.app.testdownload E/aaaa: aaaa:904 //status
05-19 22:28:34.359 8084-8084/com.devoflife.app.testdownload E/aaaa: aaaa:-111 //error
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: com.tonyodev.fetch.exception.EnqueueException: DatabaseHelper already containsFilePath a request with the filePath:/storage/emulated/0/Download/pic_mountain.jpg
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.tonyodev.fetch.DatabaseHelper.getInsertStatement(DatabaseHelper.java:147)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.tonyodev.fetch.DatabaseHelper.insert(DatabaseHelper.java:166)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.tonyodev.fetch.Fetch.enqueue(Fetch.java:292)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.devoflife.app.testdownload.PresentationAdapter.ListDownloadAdapter$3.onClick(ListDownloadAdapter.java:106)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.view.View.performClick(View.java:5610)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.view.View$PerformClick.run(View.java:22265)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.os.Looper.loop(Looper.java:154)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6077)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at java.lang.reflect.Method.invoke(Native Method)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
05-19 22:28:34.363 8084-8084/com.devoflife.app.testdownload W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
from fetch.
HI
if I want to update an downloaded file, Fetch don't allow me! and return -1 as download id.
I think that u must add a method to remove download data from fetch database without deleting the file.
if i use fetch.RemoveAll() it will work good but this method will delete my old file. so if my updat crash, then i have no file!
from fetch.
Related Issues (20)
- Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://jitpack.io/com/tonyodev/fetch2/fetch2/3.0.12/fetch2-3.0.12.pom'. HOT 3
- The free download manager application download stuck in queued in mobile
- Download groups separately
- Gradle implementation can not find HOT 1
- Parallel Download type causes to increase the network usage about five times more than what it is
- android.database.sqlite.SQLiteException
- removeListener has bugs
- when use OkHttpDownloader, App will crash with OOM HOT 1
- java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts HOT 6
- Today i face error :Failed to resolve: HOT 8
- Download is not working or resume after killing application
- This fetch instance has been closed. Create a new instance using the builder HOT 3
- Please adapt for Android 14 HOT 17
- Feth listener onComplete() called twice HOT 1
- Fetch does not throw exception when internet connection get lost
- Can't toast on a thread that has not called Looper.prepare()
- v3.2.0 build broken HOT 1
- setDownloadConcurrentLimit not work
- V3.2.0 not in maven
- Can not get v3.2.0 nor v3.2.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch.