Fix crash when opening a URL with associated text (#699)

* Fix crash when opening a URL with associated text

* Enforce using an `Activity` instead of a `Context` in `SafeUriHandler`.
This commit is contained in:
Jorge Martin Espinosa
2023-06-28 11:19:39 +02:00
committed by GitHub
parent c5a5810c05
commit fe3deeec2f
5 changed files with 45 additions and 1 deletions

View File

@@ -242,6 +242,19 @@ fun startImportTextFromFileIntent(
}
}
@Suppress("SwallowedException")
fun Context.openUrlInExternalApp(
url: String,
errorMessage: String = getString(R.string.error_no_compatible_app_found),
) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
try {
startActivity(intent)
} catch (activityNotFoundException: ActivityNotFoundException) {
toast(errorMessage)
}
}
// Not in KTX anymore
fun Context.toast(resId: Int) {
Toast.makeText(this, resId, Toast.LENGTH_SHORT).show()