簡體   English   中英

如何通過android ContentResolver.query 使用selection 和selectionArgs 在sdcard 中搜索特定文件名?

[英]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.queryselectionselectionArgssortOrder參數......在 AndroidX 的實現中根本沒有使用!

此處查看 v1.2.0 源代碼(第 409 行)

我找到的唯一解決方案是在您自己的代碼中對查詢后的結果進行過濾和排序。 是的,這有點悲傷......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM