Skip to content

fix(android): invalid column flags #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-pugs-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-native-documents/picker": patch
---

fix(android): invalid column flags error in picker
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,33 @@ class MetadataGetter(private val uriMap: MutableMap<String, Uri>) {
}
}

queryContentResolverMetadata(contentResolver, metadataBuilder, context)
val couldBeVirtualFile = pickOptions.allowVirtualFiles && DocumentsContract.isDocumentUri(context, sourceUri)
queryContentResolverMetadata(contentResolver, metadataBuilder, couldBeVirtualFile)

metadataBuilder
}

fun queryContentResolverMetadata(
contentResolver: ContentResolver,
metadataBuilder: DocumentMetadataBuilder,
context: Context
couldBeVirtualFile: Boolean
) {
val forUri = metadataBuilder.getUri()

val projection = mutableListOf(
DocumentsContract.Document.COLUMN_MIME_TYPE,
OpenableColumns.DISPLAY_NAME,
OpenableColumns.SIZE,
).apply {
if (couldBeVirtualFile) {
add(DocumentsContract.Document.COLUMN_FLAGS)
}
}.toTypedArray()

contentResolver
.query(
forUri,
arrayOf(
DocumentsContract.Document.COLUMN_MIME_TYPE,
OpenableColumns.DISPLAY_NAME,
OpenableColumns.SIZE,
DocumentsContract.Document.COLUMN_FLAGS,
),
projection,
null,
null,
null
Expand All @@ -106,7 +113,7 @@ class MetadataGetter(private val uriMap: MutableMap<String, Uri>) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// https://developer.android.com/training/data-storage/shared/documents-files#open-virtual-file
val isVirtual =
if (DocumentsContract.isDocumentUri(context, forUri)) {
if (couldBeVirtualFile) {
val cursorValue: Int =
getCursorValue(
cursor, DocumentsContract.Document.COLUMN_FLAGS, Int::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
val targetUriString = if (options.hasKey("uri")) options.getString("uri") else null

val metadataBuilder = fileOps.writeDocumentImpl(currentUriOfFileBeingExported, targetUriString, reactApplicationContext)
metadataGetter.queryContentResolverMetadata(reactApplicationContext.contentResolver, metadataBuilder, reactApplicationContext)
metadataGetter.queryContentResolverMetadata(reactApplicationContext.contentResolver, metadataBuilder, couldBeVirtualFile = false)

val arrayWithSingleResult = Arguments.createArray().apply {
val resultMap = metadataBuilder.build()
Expand Down
Loading