Android Download Manager. status is always pending

夙愿已清 提交于 2020-05-15 08:10:21

问题


I try to use Download Manager to download some files form specific URL, but the download request was never completed.

So I log some information to see what went wrong, it turns out the request is always in pending status, and the COLUMN_REASON is 0 which I couldn't find the corresponding description on the document.

COLUMN_STATUS: 1
COLUMN_REASON: 0
COLUMN_TOTAL_SIZE_BYTES: -1
COLUMN_BYTES_DOWNLOADED_SO_FAR: 0

Here is how to start a download.

val req = DownloadManager.Request(uri).apply {
    addRequestHeader("Cookie", cookie)
    allowScanningByMediaScanner()
    setTitle(fullname)
    setDescription(/* description text */)
    setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, fullname)
}
val downloadId = downloadManager.enqueue(req)

And log information for debugging.

        val filterQuery = DownloadManager.Query().setFilterById(downloadId)
        val cursor = downloadManager.query(filterQuery)
        if (cursor.moveToFirst()) {
            val total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
            val current = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
            val status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))
            val reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON))

            Log.d("App", "status: " + status.toString())
            Log.d("App", "reason: " + reason.toString())
            Log.d("App", "total: " + total.toString())
            Log.d("App", "current: " +  current.toString())
        }

So what's a possible reason that status of request was always pending and how do I debug it?

Any help is going to be appreciated.


回答1:


In my case, settings up a VPN seem to solve this problem. It looks like google services have been blocked in my network and after I set up a system global VPN the issue has gone.




回答2:


DownloadManager outputs its logs to logcat but not under your application's id, so you'll need to show logs for all apps. There should clues to the failed download in there. For example, here are a couple of my failure cases.

D/DownloadManager: [1988] Starting
W/DownloadManager: [1988] Stop requested with status 500: Internal Server Error
D/DownloadManager: [1988] Finished with status WAITING_TO_RETRY

and

W/DownloadManager: [1988] Stop requested with status 403: Unhandled HTTP response: 403 Forbidden


来源:https://stackoverflow.com/questions/53869817/android-download-manager-status-is-always-pending

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