-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to remove request from Fetch's database #44
Comments
@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? |
@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 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. |
@tonyofrancis
result log: |
Seems like there is a bug. I am looking into it |
@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));
} |
the code you post above fix half of issues, that make me confuse. Let me explain in 2 script:
Script 1 (success):
Script 2 (not success):
|
HI |
@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. |
Assume that user downloaded a file and move that file to other folder or delete it, they cannot download that file again because it save into Fetch's database. Is there a way to let user re-download?
The text was updated successfully, but these errors were encountered: