@@ -65,26 +65,33 @@ class MetadataGetter(private val uriMap: MutableMap<String, Uri>) {
65
65
}
66
66
}
67
67
68
- queryContentResolverMetadata(contentResolver, metadataBuilder, context)
68
+ val couldBeVirtualFile = pickOptions.allowVirtualFiles && DocumentsContract .isDocumentUri(context, sourceUri)
69
+ queryContentResolverMetadata(contentResolver, metadataBuilder, couldBeVirtualFile)
69
70
70
71
metadataBuilder
71
72
}
72
73
73
74
fun queryContentResolverMetadata (
74
75
contentResolver : ContentResolver ,
75
76
metadataBuilder : DocumentMetadataBuilder ,
76
- context : Context
77
+ couldBeVirtualFile : Boolean
77
78
) {
78
79
val forUri = metadataBuilder.getUri()
80
+
81
+ val projection = mutableListOf (
82
+ DocumentsContract .Document .COLUMN_MIME_TYPE ,
83
+ OpenableColumns .DISPLAY_NAME ,
84
+ OpenableColumns .SIZE ,
85
+ ).apply {
86
+ if (couldBeVirtualFile) {
87
+ add(DocumentsContract .Document .COLUMN_FLAGS )
88
+ }
89
+ }.toTypedArray()
90
+
79
91
contentResolver
80
92
.query(
81
93
forUri,
82
- arrayOf(
83
- DocumentsContract .Document .COLUMN_MIME_TYPE ,
84
- OpenableColumns .DISPLAY_NAME ,
85
- OpenableColumns .SIZE ,
86
- DocumentsContract .Document .COLUMN_FLAGS ,
87
- ),
94
+ projection,
88
95
null ,
89
96
null ,
90
97
null
@@ -106,7 +113,7 @@ class MetadataGetter(private val uriMap: MutableMap<String, Uri>) {
106
113
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
107
114
// https://developer.android.com/training/data-storage/shared/documents-files#open-virtual-file
108
115
val isVirtual =
109
- if (DocumentsContract .isDocumentUri(context, forUri) ) {
116
+ if (couldBeVirtualFile ) {
110
117
val cursorValue: Int =
111
118
getCursorValue(
112
119
cursor, DocumentsContract .Document .COLUMN_FLAGS , Int ::class .java
0 commit comments