Skip to content

Commit

Permalink
fix: crash when no browser available
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina committed May 27, 2024
1 parent c4d8002 commit 49be809
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/src/main/kotlin/com/wire/android/util/CustomTabsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}

0 comments on commit 49be809

Please sign in to comment.