ContentResolver query on Documents not filtering with selection

Viewed 466

I am trying to filter documents on display name. Here is the code:

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())
}

Here I am getting the output as [ap.apk, mytext.txt, aaa]
Whereas the expected output is just [aaa]

I have looked into other questions.
Accourding to these questions:
where clause in contentProvider's query in Android
getContentResolver().query android where clause
I also tried

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

But here also I get the same result. It would be great if someone can point me where I am making the mistake.
Thanks.

1 Answers
Related