IllegalArgumentException:调用 DownloadManager.query() 时查询中不允许列 local_filename

问题描述 投票:0回答:0

在我的应用程序中,我开始通过 DownloadManager 下载:

val downloadId: Long = downloadManager.enqueue(dr)

如果用户重新打开应用程序,我将通过以下方式检查下载状态:

fun isDownloadInProgress(): Boolean {
    val dq: DownloadManager.Query = DownloadManager.Query()
    dq.setFilterById(downloadId)
    val cursor: Cursor? = downloadManager.query(dq)
    if (cursor == null || !cursor.moveToFirst()) {
        return false
    }
    val status: Int = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))
    if (status == DownloadManager.STATUS_RUNNING || status == DownloadManager.STATUS_PENDING) {
        return true
    }
    return false
}

使用此代码,我在 Android 11 和 12 版本的小米上的 Crashlytics 破折号中发生了一些崩溃:

Caused by java.lang.IllegalArgumentException: column local_filename is not allowed in queries
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
       at android.content.ContentProviderProxy.query(ContentProviderProxy.java:481)
       at android.content.ContentResolver.query(ContentResolver.java:1219)
       at android.content.ContentResolver.query(ContentResolver.java:1151)
       at android.content.ContentResolver.query(ContentResolver.java:1107)
       at android.app.DownloadManager$Query.runQuery(DownloadManager.java:1506)
       at android.app.DownloadManager.query(DownloadManager.java:1736)
       at android.app.DownloadManager.query(DownloadManager.java:1718)

当我调用

val cursor: Cursor? = downloadManager.query(dq)
时它会抛出,因为在幕后
query()
方法
DownloadManager
调用
query(query, UNDERLYING_COLUMNS);
并且
UNDERLYING_COLUMS
包含
DownloadManager.COLUMN_LOCAL_FILENAME
列。

此列在 API 24 之后被弃用,但

DownloadManager
仍在后台使用此列。

我的问题是:

  1. 如果我使用
    DownloadManager
    不正确并且还有另一种检查下载状态的方法,有人可以建议热这样做吗?
  2. 如果这是小米 ROM 上的错误,有人可以给我问题的链接吗?

谢谢。

android android-download-manager download-manager xiaomi
© www.soinside.com 2019 - 2024. All rights reserved.