Skip to content

Commit d2f9033

Browse files
authored
Merge pull request #792 from Crustack/fix/readable-path
Fix toReadablePath if fromTreeUri fails
2 parents faa9a66 + 5227b4c commit d2f9033

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/src/main/java/com/philkes/notallyx/utils/AndroidExtensions.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,13 @@ fun Context.toReadablePath(uri: Uri): String {
533533
if (uri.authority == "com.android.externalstorage.documents") {
534534
return toReadable(uri.path!!)
535535
}
536-
val documentFile = DocumentFile.fromTreeUri(this, uri)
536+
537+
val documentFile =
538+
try {
539+
DocumentFile.fromTreeUri(this, uri)
540+
} catch (_: Exception) {
541+
null
542+
}
537543
return documentFile?.name?.let { "${uri.authority}/$it" }
538544
?: uri.path?.let { toReadable(it) }
539545
?: uri.toString()

0 commit comments

Comments
 (0)