Till when android download manager will give status of a download by download reference Id?
Asked Answered
R

2

18

I have a use case where,

I started downloading a file using android download manager, and in the middle switched off mobile. When I restarted again, the download continued and completed. I got the status by giving the download reference id. But I would like to know the status even after 10 days using that reference id.

So my question is till when android download manager will give the status of a download by download reference Id?

I looked into documentation and went through stack over flow, but unable to find the answer. Someone help me out.

Rabblerousing answered 12/2, 2017 at 6:25 Comment(1)
I have the same question... my guess is that the data will be available as long as the user did not remove the download from the Download Manager app (by long pressing it and deleting).Tiv
U
4

Android DownloaderManager is a system service. It is supposed to be running always. But there are some cases when it can't run.

The download happens via the HTTP persistent connection. It means the same established connection is used for successive HTTP request/response. The connection break means error occurs, and thus, you can't track the status by reference id.

You track via Android DownloadManager service, where Android DownloadManager service gets STATUS code from the server.

Android DownloadManager uses the content-length based download from the server. The Content-Length header will not allow streaming (link). The content-length based download has the advantage of resume, pause, partial download -- see the link1 above. So, even when you reboot the system, again it restarts (increments) the download.

The content-length based download is store and forward (link). You should forward the buffered content to the persistent storage because you have limited fixed buffers.

The Android DownloadManager has ERROR_CANNOT_RESUME int flag (link). The ERROR_CANNOT_RESUME is based on the COLUMN_STATUS flag. There are two types of COLUMN STATUS: STATUS_PAUSED or STATUS_FAILED. Before system turns off, the system via the BroadcastReceiver sends Android DownloadManager service about turn off. The Android DownloadManager then activates STATUS_PAUSED flag. And, when next time you restart the device, the system service runs automatically, checks if STATUS_PAUSED then starts downloading again.

Answer: so until there happens error (in client side, connection or server-side) or you are not done downloading the file (it means until STATUS_SUCCESSFUL), you keep getting status from the Android DownloadManager. You can't get status when there happens STATUS_FAILED -- it says download will not be retried (link).

How STATUS_FAILED happens? Client's DownloadManager service detects HTTP status code 4XX (Server guesses client is erred) and 5XX (Server detects server is erred) (link), now STATUS_FAILED becomes true.

Some other situations: When Clients keeps turned-off and based on server-logic, the server can terminate the connection with the timeout. So, this control is explicitly based on different HTTP server. We can't ask these many days here. We don't know the server-side logic. The status_codes are based on the server. When server decides client has failed, and the server then does timeout the connection making STATUS_FAILED active at the server-side. clients must be prepared for TCP connections to disappear at arbitrary times, and must be able to re-establish the connection and retry the HTTP request. A prematurely closed connection should not be treated as an error; an error would only be signaled if the attempt to re-establish the connection fails. Your question doesn't have an exact answer.

Note: TCP connections to disappear at arbitrary times (link) is the main logic here that can resume your connection after a certain number of days of your device turned off.

1) On STATUS_FAILED, you can't continue track further data.

2) On If COLUMN_STATUS is neither STATUS_FAILED nor STATUS_PAUSED, this column's value is undefined, here you may not be able to track further data.

-- Anything in other than above two conditions, the download is in progress.

Ulaulah answered 3/8, 2017 at 3:1 Comment(10)
@Gautam Thanks for the answer, I did not get the answer completely. My question is, Consider I started a download and have download reference id, now the status may become STATUS_FAILED, STATUS_PAUSED, STATUS_SUCCESSFUL or Whatever. Now till how many days or months, the android system will give status for given download reference id?Rabblerousing
@San, I apologize, I understood now. Those id are overridden continuously on each download occurs. When status successful and completes, now, the whole process becomes the part of GC, Garbage Collection, which based on your system removes those variables later.Ulaulah
Same things when Connection breaks. Once the connection fails ( I'm not saying premature fail -- read answer again), it means fail forever. You can't reestablish the same connection again. Now, again, the whole heap operation is taken care by GC.Ulaulah
@Gautham, So are you saying we can't be assured till when the android download manager will give the status and the same id can be overridden by another download?Rabblerousing
Status_pending gets overridden all the time until your particular download completes. I never talked about two different downloads. Please read all the link above.Ulaulah
Ask yourself how are you getting status codes? Because server is giving http status codes, and based on various http status codes from server, the client ( Download manager) service creates it's own status codes ( eg, STATUS_PENDING). Those clients codes you can read using that DownloadManaget system service.Ulaulah
The overall http communication concept is not easy to understand, that's why I provided so many links.Ulaulah
That HTTP part is okay. As you said GC will remove the download reference ids. When will it remove? after how many days?Rabblerousing
In Java we don't know that things. If system needs to free, then it can immediately free that from your cache, and to further removes that I'd again from storage. Again this happens if you are completed with downloading or you got error.Ulaulah
Let us continue this discussion in chat.Ulaulah
W
-2

You can use SharedPreferences to store your download reference ID. Something like this -

SharedPreferences settings = getSharedPreferences("DownloadIDS", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putLong("downloadIds", downloadID);
editor.commit();

You can retrieve the ID later when using this

SharedPreferences downloadids = context.getSharedPreferences("DownloadIDS", 0);
long savedDownloadIds = downloadids.getLong("downloadIds", 0);
Wavellite answered 1/8, 2017 at 19:43 Comment(6)
Thanks for the answer. Here my question is not about storing download reference ID My question is about till when the android system will give status for a given download reference ID?Rabblerousing
Please focus on the question So my question is till when android download manager will give the status of a download by download reference Id?Sneer
I understand the question. But I'm giving a workaround which solves the OP's problem in a different way. I don't think it merits downvotes.Wavellite
In some ways, the answer is not out of context. Saving the download id is the first step, querying it would obviously be the next. Instead of trying to figure out how long the download manager will keep the download status, you could just query the download manager and handle the response appropriately...Conic
@shegzy Thanks for comment, I can query. But my use case is different. The user may open the app after one month. Now, will I get the status from android download manager for given download reference Id?. That's what I would like to know.Rabblerousing
Yes you would request for the status, handle the response and give an output to the userConic

© 2022 - 2024 — McMap. All rights reserved.