diff --git a/app/src/main/kotlin/com/wire/android/util/CustomTabsHelper.kt b/app/src/main/kotlin/com/wire/android/util/CustomTabsHelper.kt index e1c55c41e97..a3b56ce2870 100644 --- a/app/src/main/kotlin/com/wire/android/util/CustomTabsHelper.kt +++ b/app/src/main/kotlin/com/wire/android/util/CustomTabsHelper.kt @@ -18,25 +18,37 @@ package com.wire.android.util +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.graphics.BitmapFactory import android.net.Uri import androidx.browser.customtabs.CustomTabsIntent +import com.wire.android.AppJsonStyledLogger import com.wire.android.R +import com.wire.kalium.logger.KaliumLogLevel object CustomTabsHelper { fun launchUrl(context: Context, url: String) = launchUri(context, Uri.parse(url)) + @JvmStatic fun launchUri(context: Context, uri: Uri) { val builder = CustomTabsIntent.Builder() .setCloseButtonIcon(BitmapFactory.decodeResource(context.resources, R.drawable.ic_close)) .setShareState(CustomTabsIntent.SHARE_STATE_OFF) .setShowTitle(true) - - val customTabsIntent = builder.build() - customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse("android-app://" + context.packageName)) - customTabsIntent.launchUrl(context, uri) + try { + val customTabsIntent = builder.build() + customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse("android-app://" + context.packageName)) + customTabsIntent.launchUrl(context, uri) + } catch (exception: ActivityNotFoundException) { + AppJsonStyledLogger.log( + level = KaliumLogLevel.ERROR, + leadingMessage = "CustomTabsHelper", + jsonStringKeyValues = mapOf("targetURI" to uri), + error = exception + ) + } } }