-
Notifications
You must be signed in to change notification settings - Fork 840
Fix: Restore ms[df] URI handling logic #1925
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e3b7141
Fix: Restore ms[df] URI handling logic (fixes #1922, fixes #1916)
vicajilau d026539
feat: add Android FileUtils for managing file selection, saving, and …
vicajilau 91ba663
Fix(Android): pass Context to getFullPathFromTreeUri to fix undefined…
vicajilau e0ebce6
Refactor: Remove unused parameter in `createImageFile` and use `dropL…
vicajilau e5c7c34
Updates the package version to 10.3.8 and updates the changelog.
vicajilau 45314e0
fix(android): Update Intent actions for file picking
vicajilau 993c345
docs(android): Add KDoc and intent rationale to FileUtils
vicajilau 0fde627
Update android/src/main/kotlin/com/mr/flutter/plugin/filepicker/FileU…
navaronbracke 730a609
Update CHANGELOG.md
vicajilau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,7 @@ object FileUtils { | |
| uri, | ||
| DocumentsContract.getTreeDocumentId(uri) | ||
| ) | ||
| val dirPath = getFullPathFromTreeUri(uri) | ||
| val dirPath = getFullPathFromTreeUri(uri, activity) | ||
| if (dirPath != null) { | ||
| finishWithSuccess(dirPath) | ||
| } else { | ||
|
|
@@ -142,7 +142,7 @@ object FileUtils { | |
| if (type == "dir") { | ||
| intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) | ||
| } else { | ||
| if (type != "*/*") { | ||
| if (type == "image/*") { | ||
navaronbracke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| intent = Intent(Intent.ACTION_PICK) | ||
| val uri = (Environment.getExternalStorageDirectory().path + File.separator).toUri() | ||
| intent.setDataAndType(uri, type) | ||
|
|
@@ -159,7 +159,7 @@ object FileUtils { | |
| intent.putExtra(Intent.EXTRA_MIME_TYPES, allowedExtensions) | ||
| } | ||
| } else { | ||
| intent = Intent(Intent.ACTION_GET_CONTENT).apply { | ||
| intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { | ||
navaronbracke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| addCategory(Intent.CATEGORY_OPENABLE) | ||
| type = [email protected] | ||
| if (!allowedExtensions.isNullOrEmpty()) { | ||
|
|
@@ -413,7 +413,7 @@ object FileUtils { | |
| try { | ||
| context.contentResolver.openInputStream(originalImageUri).use { imageStream -> | ||
| val compressFormat = getCompressFormat(context, originalImageUri) | ||
| val compressedFile = createImageFile(context, originalImageUri, compressFormat) | ||
| val compressedFile = createImageFile(context, compressFormat) | ||
| val originalBitmap = BitmapFactory.decodeStream(imageStream) | ||
| // Compress and save the image | ||
| val fileOutputStream = FileOutputStream(compressedFile) | ||
|
|
@@ -429,7 +429,7 @@ object FileUtils { | |
| } | ||
|
|
||
| @Throws(IOException::class) | ||
| private fun createImageFile(context: Context, uri: Uri, compressFormat: Bitmap.CompressFormat): File { | ||
| private fun createImageFile(context: Context, compressFormat: Bitmap.CompressFormat): File { | ||
| val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()) | ||
| val imageFileName = "IMAGE_" + timeStamp + "_" | ||
| val storageDir = context.cacheDir | ||
|
|
@@ -557,7 +557,7 @@ object FileUtils { | |
| } | ||
|
|
||
| @JvmStatic | ||
| fun getFullPathFromTreeUri(treeUri: Uri?): String? { | ||
| fun getFullPathFromTreeUri(treeUri: Uri?, context: Context): String? { | ||
| if (treeUri == null) { | ||
| return null | ||
| } | ||
|
|
@@ -569,6 +569,14 @@ object FileUtils { | |
| Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path | ||
| if (docId == "downloads") { | ||
| return extPath | ||
| } else if (docId.matches("^ms[df]:.*".toRegex())) { | ||
navaronbracke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Handle "msf:" (Media Store File) and "msd:" (Media Store Directory) prefixes. | ||
| // These are commonly seen on Android 10+ (API 29+) when selecting files from the | ||
| // "Downloads" category in the system picker. | ||
| // Note that this does not happen on all devices. | ||
| // Example URI: content://com.android.providers.downloads.documents/document/msf:1000000033 | ||
| val fileName = getFileName(treeUri, context) | ||
| return "$extPath/$fileName" | ||
| } else if (docId.startsWith("raw:")) { | ||
| return docId.split(":".toRegex()).dropLastWhile { it.isEmpty() } | ||
| .toTypedArray()[1] | ||
|
|
@@ -580,13 +588,13 @@ object FileUtils { | |
| var volumePath = getPathFromTreeUri(treeUri) | ||
|
|
||
| if (volumePath.endsWith(File.separator)) { | ||
| volumePath = volumePath.substring(0, volumePath.length - 1) | ||
| volumePath = volumePath.dropLast(1) | ||
| } | ||
|
|
||
| var documentPath = getDocumentPathFromTreeUri(treeUri) | ||
|
|
||
| if (documentPath.endsWith(File.separator)) { | ||
| documentPath = documentPath.substring(0, documentPath.length - 1) | ||
| documentPath = documentPath.dropLast(1) | ||
| } | ||
| return if (documentPath.isNotEmpty()) { | ||
| if (volumePath.endsWith(documentPath)) { | ||
|
|
@@ -623,4 +631,4 @@ object FileUtils { | |
|
|
||
| file.delete() | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.