DownloadManager sends STATUS_SUCCESSFUL for failed download
Asked Answered
H

1

8

Okay, I'm downloading files (images). I want to send a message with local URI for the image when the download is completed. But 20% of time I'm getting this:

6-01 18:46:39.900: INFO/DownloadManager(412): Initiating request for download 605
06-01 18:46:39.910: WARN/DownloadManager(412): Aborting request for download 605: Trying to resume a download that can't be resumed
06-01 18:46:39.910: INFO/ololo(2826): Okay, I'll broadcast.
06-01 18:46:39.990: WARN/ImageView(2826): Unable to open content: content://downloads/my_downloads/605
    java.io.FileNotFoundException: No filename found.
    at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:145)...
06-01 18:46:39.990: INFO/System.out(2826): resolveUri failed on bad bitmap uri: content://downloads/my_downloads/605
06-01 18:46:39.990: INFO/ololo(2826): content://downloads/my_downloads/605 was set for android.widget.ImageView@408a2cf0

Here is the code

Long downloadId = downloadIds.get(this);

if(downloadId == intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(downloadId);
    Cursor cursor = downloadManager.query(query);

    if(cursor.moveToFirst()) {

        switch (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
            case DownloadManager.STATUS_SUCCESSFUL : {
                Log.i("ololo", "Okay, I'll broadcast.");
                // Broadcasting
                break;
            }
            case DownloadManager.STATUS_FAILED : {
                Log.i("ololo", "Bad, I won't broadcast.");
                int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
                if(reason == DownloadManager.ERROR_CANNOT_RESUME || reason == DownloadManager.ERROR_UNKNOWN) {
                    // Rerun download
                }
                break;
            }
            default:
                break;
        }
    }
}
Headforemost answered 1/6, 2012 at 15:8 Comment(4)
Hi, I'm having the same problem. have you solved it somehow or understood what's wrong?Simmon
@TalKanel The problem is happening ONLY with Samsung devices (Galaxy Tab 10.1 or something else, on 3.2, or 2.3.3, or 4.0 – this doesn't matter, never happened to any HTC). I think there is their own buggy realization of the DownloadManager. So my team leader wrote her own realization and it works well.Headforemost
too bad, I need to use it in samsung tablets P7510 and P5110 (GALAXY TAB 10.1 ONE and TWO), and I need it to work on the specific OS versions you mentioned.. so I guess I have to implemment my own workaround..Simmon
Download Manager success status still fires twice on at least LG Nexus 4.4.2 (see the bug report link in below answer). I spent a good half of the day with this until finally gave up. Rolling something with loopj.com/android-async-http or code.google.com/p/google-http-java-client or code.google.com/p/basic-http-client which look all promising and provide an abstraction for AsyncTask.Vinic
C
8

DownloadManager is buggy and doesn't work correctly. This bug was filed with Google a while back:

https://code.google.com/p/android/issues/detail?id=18462

For single file download, you could workaround this by specifying a unique directory to download to specifically for this purpose, and just take whatever you get in that directory upon DownloadManager.STATUS_SUCCESSFUL.
For multi-file downloads, I can't think of a workaround at the moment, unless you have the ability to rename files at the source.

Cabalist answered 2/3, 2013 at 1:53 Comment(4)
Yes, using HTTP ETags probably would resolve this problem. However, the use of HTTP ETags is optional in the HTTP spec, and therefore, using ETags to solve this problems depends on having direct admin access to the web server in order to add ETags support. I still claim that DownloadManager is buggy because it fails to work without ETags support.Cabalist
I am facing bit similar problem...getting STATUS_FAILED for running download...have any idea why?Substandard
DownloadManager is not completing downloads for files that have a size higher than Integer.MAX_VALUE (~2.1 GB) for OS less than 4.2.2. Issue reported here.Outing
This bug is still not fixed yet. Can you suggest any alternative way to check whether the download is SUCCESSFUL or FAILED while using DownloadManager class?Belongings

© 2022 - 2024 — McMap. All rights reserved.