【问题标题】:ContentResolver query on Documents not filtering with selectionContentResolver 查询未通过选择过滤的文档
【发布时间】:2020-12-28 10:14:54
【问题描述】:

我正在尝试过滤显示名称的文档。代码如下:

val files = ArrayList<String>(0)
val uri = DocumentsContract.buildChildDocumentsUriUsingTree(rootUri, DocumentsContract.getTreeDocumentId(rootUri))
val searchQuery = "${DocumentsContract.Document.COLUMN_DISPLAY_NAME} LIKE ?"
val cursor = cResolver.query(uri, arrayOf(DocumentsContract.Document.COLUMN_DISPLAY_NAME), searchQuery, arrayOf("'%aaa%'"), null)
while (cursor?.moveToNext() == true){
    files.add(cursor.getString(0).toString())
}

在这里我得到的输出为[ap.apk, mytext.txt, aaa]
而预期的输出只是[aaa]

我已经研究了其他问题。
根据这些问题:
where clause in contentProvider's query in Android
getContentResolver().query android where clause
我也试过了

val searchQuery = "${DocumentsContract.Document.COLUMN_DISPLAY_NAME} like '%aaa%'"
val cursor = cResolver.query(uri, arrayOf(DocumentsContract.Document.COLUMN_DISPLAY_NAME), searchQuery, null, null)

但在这里我也得到了相同的结果。如果有人能指出我在哪里犯了错误,那就太好了。
谢谢。

【问题讨论】:

  • 您解决了这个问题吗?同样的问题,我可以把垃圾作为查询,它不会导致错误,所以它被忽略了
  • @Neo 不,没有解决方案。我必须遍历光标(cursor.moveToNext())并手动过滤。
  • 自您发布此消息以来运气好吗?我也有同样的问题。

标签: android-contentresolver android-cursor


【解决方案1】:

A very similar question has been already askedunsatisfying answer 是忽略 uri(代表文件夹)的后代的选择子句和排序顺序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2012-09-08
    • 2015-11-14
    • 2018-08-14
    相关资源
    最近更新 更多