Search code examples
javaandroiddownloadandroid-download-manager

DownloadManager cursor attribute COLUMN_LOCAL_FILENAME is null when downloading fails


I'm building a fallback for my DownloadManager which shall restart failed downloads.

I stuck to vogella's example building my download manager functionality.

if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);

...

} else if (DownloadManager.STATUS_FAILED == c.getInt(columnIndex)) { 

         colIndex = c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME);
         String localFilename = c.getString(colIndex);

}

The "failed"-case is working but my localFilename variable is null.

BTW: The COLUMN_URI is working.

Any ideas how I can access the target/local path or filename?


Solution

  • The local filename is null because downloading failed. There is no local file to reference.

    Cf. the documentation for DownloadManager.html#getUriForDownloadedFile (emphasis added):

    Returns the Uri of the given downloaded file id, if the file is downloaded successfully. Otherwise, null is returned.