10

I have been using the DownloadManager APIs to handle downloads in one app for about 3 years. Recently I had some users on Android Pie complaining that sometimes downloads get stuck for several minutes before actually starting, thus compromising the UX: some of them had to reinstall the app to make them work correctly, some others had the issue fixed itself over time. Please note that I haven't set any special settings to the DownloadManager.Request instances (e.g. allowedNetworkTypes, setRequiresCharging, ...).

My understanding of the problem is that requests get stuck in the pending or paused status for a long time before getting started. Didn't notice any significant changes introduced in the SDK 28, although it's not important since I'm targeting API level 27.

Has anyone experienced something similar and came up with some workarounds? Thank you

Matteo Innocenti
  • 231
  • 2
  • 10
  • 1
    maybe they are pending since there is a fixed limit of current downloads and that limit has been reached... but its just wild speculation – pskink Aug 28 '18 at 10:52
  • Bear in mind that the implementation of `DownloadManager` not only varies by OS version, but can vary by device manufacturer. `DownloadManager` has never been a good choice if the download is time-sensitive. – CommonsWare Aug 28 '18 at 11:02
  • @pskink there is a limit for sure but apparently there wasn't anything else queued at that moment. – Matteo Innocenti Sep 14 '18 at 09:41
  • @CommonsWare Really appreciate your comment, but I have reasons to keep using such a helpful system service. I was just asking myself about any changes in Android Pie since users across all the other OS versions (and manufacturers) aren't complaining at all about it – Matteo Innocenti Sep 14 '18 at 09:43
  • 2
    So it turns out that deleting the Download Manager app cache and data just once completely restores the functionality, meaning that enqueued downloads start immediately (of course taking into account the concurrency limit). – Matteo Innocenti Sep 14 '18 at 09:45
  • @MatteoInnocenti Hi. I just experienced the same issue right now on a Pixel 2 9.0 device. Can you tell me how did you reset the Download Manager cache ? I didn't found it in setting's applications list. Thx. – lithos35 Sep 14 '18 at 15:59
  • @lithos35 see here under "clear cache & data from download manager" https://support.google.com/googleplay/answer/7512202?hl=en – Matteo Innocenti Sep 16 '18 at 08:43
  • Did you got any solution.I also face the same issue in pie update – Lavanya Velusamy Nov 09 '18 at 01:49
  • https://stackoverflow.com/questions/53493077/files-are-not-downloading-on-android-pie-9-0-xiaomi-mi-a2-using-download-mange/53845690#53845690 – Quick learner Dec 19 '18 at 06:33

1 Answers1

6

As mentioned in the comments above, clearing the Download manager cache and data resolves this problem on Android 9 Pie. To clear these settings, you need to go to Apps & notifications, click the option to See all apps, tap the options menu in the upper-right corner, select Show system, select Download Manager from the list, tap on Storage, then clear the cache and storage.

When troubleshooting this problem I discovered that when trying to use DownloadManager to download a file to a public directory, the following warning was written to the log if a public download location was used:

DownloadManager: Path appears to be invalid: /storage/emulated/0/Download/File Name

This error appears irrespective of whether the app has the storage permission. However, it appears to be a false warning that is logged by isFilenameValidInExternalPackage() (source code) when checking if the file is outside an app directory and is run even if the app has the storage permission. As such, this false warning continues to appear even after clearing DownloadManager's cache and storage, although the download works anyway.

Edit: this problem appears to recur periodically. Typically, force stopping Download Manager resolves it temporarily. Hopefully Google releases a permanent fix.

Soren Stoutner
  • 1,413
  • 15
  • 21