![](/img/trans.png)
[英]selectionArgs in ContentResolver.query(…) can be a subquery?
[英]How to search for a specific filename in the sdcard by android ContentResolver.query using selection and selectionArgs?
我已經通過 DocumentsContract.BuildDocumentUriUsingTree 將 uri 檢索到 sdcard,現在我正在嘗試在包含許多文件的目錄中查找文件。 我嘗試了以下代碼片段:
selection = "_display_name='111'"; //I haven't use selectionArgs here for simplicity
context.contentResolver.query(childrenUri, projection, selection, null, null)
我也試過“_display_name=?” 並使用 selectionArgs 但它看起來提供者完全忽略我的選擇並始終返回目錄中的所有文件。
我已經用三星 S7 - Android 8 對其進行了測試。如何讓查詢只查找特定的文件名?
假設您使用的提供程序是androidx.core.content.FileProvider
(根據您在清單中聲明的內容),則FileProvider.query
的selection
、 selectionArgs
和sortOrder
參數......在 AndroidX 的實現中根本沒有使用!
在此處查看 v1.2.0 源代碼(第 409 行)
我找到的唯一解決方案是在您自己的代碼中對查詢后的結果進行過濾和排序。 是的,這有點悲傷......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.