Skip to content

Commit 43df08e

Browse files
committed
correct external storage folder path #1801
1 parent 3f10a6b commit 43df08e

File tree

1 file changed

+15
-1
lines changed
  • android/src/main/kotlin/com/mr/flutter/plugin/filepicker

1 file changed

+15
-1
lines changed

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

0 commit comments

Comments
 (0)