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.
A very similar question has been already asked, the unsatisfying answer is that the selection clauses and sort orders are ignored for descendants of the uri (which represents a folder).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With