-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6d0355a
commit 04efd01
Showing
1 changed file
with
12 additions
and
3 deletions.
There are no files selected for viewing
15 changes: 12 additions & 3 deletions
15
android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/IntentUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} |