简体   繁体   English

使用 ContentResolver 查询 DocumentsContract Uri 时,如何检查是否可以读取文档?

[英]How do I check if I can read a document when using ContentResolver to query a DocumentsContract Uri?

I'm using a DocumentsContract query to try to speed up reading a folder.我正在使用DocumentsContract查询来尝试加快读取文件夹的速度。 I got most data but I'm struggling with the flag that tells me if I can read the document.我得到了大部分数据,但我正在努力处理告诉我是否可以阅读文档的标志。

This is the query:这是查询:

contentResolver.query(uri, arrayOf(
                DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_MIME_TYPE, DocumentsContract.Document.COLUMN_LAST_MODIFIED, DocumentsContract.Document.COLUMN_SIZE, DocumentsContract.Document.COLUMN_FLAGS), null, null, null)

DocumentsContract.Document.COLUMN_FLAGS has in its documentation: DocumentsContract.Document.COLUMN_FLAGS在其文档中有:

     /**
     * Flags that apply to a document. This column is required.
     * <p>
     * Type: INTEGER (int)
     *
     * @see #FLAG_DIR_BLOCKS_OPEN_DOCUMENT_TREE
     * @see #FLAG_DIR_PREFERS_GRID
     * @see #FLAG_DIR_PREFERS_LAST_MODIFIED
     * @see #FLAG_DIR_SUPPORTS_CREATE
     * @see #FLAG_PARTIAL
     * @see #FLAG_SUPPORTS_COPY
     * @see #FLAG_SUPPORTS_DELETE
     * @see #FLAG_SUPPORTS_METADATA
     * @see #FLAG_SUPPORTS_MOVE
     * @see #FLAG_SUPPORTS_REMOVE
     * @see #FLAG_SUPPORTS_RENAME
     * @see #FLAG_SUPPORTS_SETTINGS
     * @see #FLAG_SUPPORTS_THUMBNAIL
     * @see #FLAG_SUPPORTS_WRITE
     * @see #FLAG_VIRTUAL_DOCUMENT
     * @see #FLAG_WEB_LINKABLE
     */

I can see WRITE there but what about READ ?我可以在那里看到WRITEREAD呢?

val canRead = context.checkCallingUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) == PackageManager.PERMISSION_GRANTED

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查ContentResolver是否正忙 - How can I check if a ContentResolver is busy 使用 mp4parser ,如何处理从 Uri 和 ContentResolver 获取的视频? - Using mp4parser , how can I handle videos that are taken from Uri and ContentResolver? 如何在Android中使用ContentResolver进行不区分大小写的查询? - How do I make a case insensitive query with ContentResolver in Android? 如何通过一个查询从ContentResolver获取电话号码? - How do I get a phone number from a ContentResolver with a single query? 如何使用ContentResolver获取帐户类型? - How can i get account type using ContentResolver? 如何使用contentResolver更新专辑封面路径? - How can I update the album art path using contentResolver? 如何从 DocumentsContract.Document 中获取 MediaStore 元数据? - How can you get MediaStore metadata from a DocumentsContract.Document? 如何从ContentResolver查询中获取跟踪Uri? - How to get track Uri from ContentResolver query? 如何使用 ContentResolver 从 Android 11 上另一个应用程序导出的 ContentProvider 读取数据? - How do I use ContentResolver to read data from another app's exported ContentProvider on Android 11? 无法使用ContentResolver.openInputStream(Uri)读取文件 - Cannot read file using ContentResolver.openInputStream(Uri)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM