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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With