DownloadManager requests delayed on Android Pie

戏子无情 提交于 2019-12-19 02:01:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/52055952/downloadmanager-requests-delayed-on-android-pie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!