This repository was archived by the owner on Mar 15, 2026. It is now read-only.
Treat last_modified and mime_type columns from DocumentProvider as nullable#100
Open
saket wants to merge 1 commit intogoogle:mainfrom
Open
Treat last_modified and mime_type columns from DocumentProvider as nullable#100saket wants to merge 1 commit intogoogle:mainfrom
saket wants to merge 1 commit intogoogle:mainfrom
Conversation
saket
commented
Jan 4, 2023
| // These two columns are optional and may not be implemented by the providing app. | ||
| val lastModifiedTime = cursor.getLongOrNull(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED)) | ||
| val mimeType = cursor.getStringOrNull(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)) | ||
| ?: contentResolver.getType(uri) |
Contributor
Author
There was a problem hiding this comment.
I noticed ContentResolver#getType(Uri) is a nice fallback and works in most cases.
saket
commented
Jan 4, 2023
| // DocumentsContract.Document.COLUMN_SIZE | ||
| val size = cursor.getLong(3) | ||
| val displayName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) | ||
| val size = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE)) |
Contributor
Author
There was a problem hiding this comment.
I replaced the two DocumentsContract.Document.* column names with OpenableColumns.* because the class-doc of OpenableColumns makes it clear that document providers are only required to implement these two columns.
I can undo this if you want because they do look slightly inconsistent with DocumentsContract.Document.COLUMN_LAST_MODIFIED and DocumentsContract.Document.COLUMN_MIME_TYPE.
saket
commented
Jan 4, 2023
| put(Uri::class, uri) | ||
| put(MetadataExtras.DisplayName::class, MetadataExtras.DisplayName(displayName)) | ||
| if (mimeType != null) { | ||
| put(MetadataExtras.MimeType::class, MetadataExtras.MimeType(mimeType)) |
Contributor
Author
There was a problem hiding this comment.
This will be a breaking change for apps that always expect a mime type to be present, but maybe that's okay considering you've only done alpha releases so far?
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenableColumns makes it clear that a
DocumentProvideris only required to implement two columns:OpenableColumns.DISPLAY_NAMEandOpenableColumns.SIZE. All other columns are optional and can causemodernstorageto crash because it expectslast_modifiedandmime_typeto be always present.Example 1: Files by Google
Example 2: Cx file explorer
This PR treats those two columns as nullable. Thoughts?