Skip to content

Commit c3f0162

Browse files
authored
Merge pull request #1806 from ekuleshov/android_external_storage_1801
correct external storage folder path on Android
2 parents 3f10a6b + 3427c08 commit c3f0162

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 10.1.9
2+
### Android
3+
- Fixed an issue when a folder is selected on an external storage [#1801](https://github.com/miguelpruivo/flutter_file_picker/issues/1801)
4+
15
## 10.1.8
26
### Android
37
- Fixed an issue when a folder is selected [#1802](https://github.com/miguelpruivo/flutter_file_picker/issues/1802)

android/src/main/kotlin/com/mr/flutter/plugin/filepicker/FileUtils.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,21 @@ object FileUtils {
503503
private fun getPathFromTreeUri(uri: Uri): String {
504504
val docId = DocumentsContract.getTreeDocumentId(uri)
505505
val parts = docId.split(":")
506-
return "${Environment.getExternalStorageDirectory()}/${parts.last()}"
506+
507+
// Check if the URI corresponds to external storage
508+
return if (parts.size > 1) {
509+
val volumeId = parts[0]
510+
val path = parts[1]
511+
512+
// Map volume ID to external storage path
513+
if ("primary".equals(volumeId, ignoreCase = true)) {
514+
"${Environment.getExternalStorageDirectory()}/$path"
515+
} else {
516+
"/storage/$volumeId/$path"
517+
}
518+
} else {
519+
"${Environment.getExternalStorageDirectory()}/${parts.last()}"
520+
}
507521
}
508522

509523
@JvmStatic

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
33
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
44
repository: https://github.com/miguelpruivo/flutter_file_picker
55
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
6-
version: 10.1.8
6+
version: 10.1.9
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)