Skip to content

Commit

Permalink
[#3954] Update resolveAndStartIntent with more error prone approach (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan authored Sep 16, 2024
1 parent 6d0355a commit 04efd01
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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() }
}
}

0 comments on commit 04efd01

Please sign in to comment.