From 04efd016f2663faf2fe637a249c7e96bbecfa46c Mon Sep 17 00:00:00 2001 From: Mustafa Ozhan Date: Mon, 16 Sep 2024 13:11:40 +0200 Subject: [PATCH] [Oztechan/CCC#3954] Update resolveAndStartIntent with more error prone approach (#3955) --- .../ccc/android/ui/mobile/util/IntentUtil.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt b/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt index 2a2e525955..c36b1b09aa 100644 --- a/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt +++ b/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt @@ -1,13 +1,22 @@ package com.oztechan.ccc.android.ui.mobile.util +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import co.touchlab.kermit.Logger +@Suppress("TooGenericExceptionCaught") fun Context.resolveAndStartIntent(intent: Intent) { - intent.resolveActivity(packageManager)?.let { - startActivity(intent) - } ?: Exception("No activity found to handle the intent: $intent").let { + try { + intent.resolveActivity(packageManager)?.let { + startActivity(intent) + null + } ?: Exception("No activity found to handle the intent: $intent") + } catch (e: ActivityNotFoundException) { + Exception("Unable to open link", e) + } catch (e: Exception) { + Exception("An error occurred", e) + }.let { Logger.e(it) { it.message.orEmpty() } } }