Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 66b7f57

Browse files
committed
fix: catch exceptions while launching OPEN_DOCUMENT_TREE intent
1 parent 28bd0ff commit 66b7f57

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

common/src/main/java/com/itsaky/androidide/fragments/BaseFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import androidx.core.provider.DocumentsContractCompat.buildDocumentUriUsingTree
3939
import androidx.core.provider.DocumentsContractCompat.getTreeDocumentId
4040
import androidx.documentfile.provider.DocumentFile
4141
import androidx.fragment.app.Fragment
42+
import com.itsaky.androidide.common.R
4243
import com.itsaky.androidide.resources.R.string
4344
import com.itsaky.androidide.utils.flashError
4445
import java.io.File
@@ -106,7 +107,11 @@ open class BaseFragment @JvmOverloads constructor(contentLayoutId: Int = 0) :
106107

107108
protected fun pickDirectory(dirCallback: OnDirectoryPickedCallback?) {
108109
this.callback = dirCallback
109-
this.startForResult.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE))
110+
try {
111+
this.startForResult.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE))
112+
} catch (e: Exception) {
113+
requireActivity().flashError(getString(R.string.msg_dir_picker_failed, e.message))
114+
}
110115
}
111116

112117
fun interface OnDirectoryPickedCallback {

resources/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,5 @@
541541
<string name="idepref_java_diagnosticEnabled_title">Diagnostics enabled</string>
542542
<string name="idepref_java_diagnosticsEnabled_summary">(EXPERIMENTAL) Whether the Java source files should be analyzed for errors or not.</string>
543543
<string name="title_reload_color_schemes">Reload color schemes</string>
544+
<string name="msg_dir_picker_failed">Failed to start directory picker : %1$s</string>
544545
</resources>

0 commit comments

Comments
 (0)