Skip to content

Commit 0844a79

Browse files
committed
Don't let invalid initial dir URI kill dir picker call
1 parent 20bc343 commit 0844a79

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

android/src/main/kotlin/codeux/design/filepicker/file_picker_writable/FilePickerWritableImpl.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,22 @@ class FilePickerWritableImpl(
7979
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
8080
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
8181
if (initialDirUri != null) {
82-
val parsedUri = Uri.parse(initialDirUri).let {
83-
val context = requireActivity().applicationContext
84-
if (DocumentsContract.isDocumentUri(context, it)) {
85-
it
86-
} else {
87-
DocumentsContract.buildDocumentUriUsingTree(it, DocumentsContract.getTreeDocumentId(it))
82+
try {
83+
val parsedUri = Uri.parse(initialDirUri).let {
84+
val context = requireActivity().applicationContext
85+
if (DocumentsContract.isDocumentUri(context, it)) {
86+
it
87+
} else {
88+
DocumentsContract.buildDocumentUriUsingTree(
89+
it,
90+
DocumentsContract.getTreeDocumentId(it)
91+
)
92+
}
8893
}
94+
putExtra(DocumentsContract.EXTRA_INITIAL_URI, parsedUri)
95+
} catch (e: Exception) {
96+
plugin.logDebug("exception while preparing document picker initial dir", e)
8997
}
90-
putExtra(DocumentsContract.EXTRA_INITIAL_URI, parsedUri)
9198
}
9299
}
93100
}

0 commit comments

Comments
 (0)