mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-24 08:45:31 +00:00
android: replacing a crash with an alert when opening broken Uri (#4674)
* android: replacing a crash with an alert when opening broken Uri * strings --------- Co-authored-by: Evgeny <evgeny@poberezkin.com>
This commit is contained in:
committed by
GitHub
parent
38fa4c231f
commit
c72c461306
+1
@@ -18,5 +18,6 @@ val NotificationsMode.requiresIgnoringBattery
|
||||
lateinit var APPLICATION_ID: String
|
||||
|
||||
fun Uri.toURI(): URI = URI(toString().replace("\n", ""))
|
||||
fun Uri.toURIOrNull(): URI? = try { toURI() } catch (e: Exception) { null }
|
||||
|
||||
fun URI.toUri(): Uri = Uri.parse(toString())
|
||||
|
||||
+9
-4
@@ -241,10 +241,15 @@ private fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int,
|
||||
}
|
||||
|
||||
actual fun getFileName(uri: URI): String? {
|
||||
return androidAppContext.contentResolver.query(uri.toUri(), null, null, null, null)?.use { cursor ->
|
||||
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||
cursor.moveToFirst()
|
||||
cursor.getString(nameIndex)
|
||||
return try {
|
||||
androidAppContext.contentResolver.query(uri.toUri(), null, null, null, null)?.use { cursor ->
|
||||
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||
cursor.moveToFirst()
|
||||
// Can make an exception
|
||||
cursor.getString(nameIndex)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user