Skip to content

Commit

Permalink
try catch intent handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MorenoTropical authored and lukstbit committed May 19, 2024
1 parent 555a8e0 commit 9a49a9f
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,21 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) {
}

private fun handleIntentUrl(url: Uri, flags: Int) {
val intent = Intent.parseUri(url.toString(), flags)
if (packageManager.resolveActivityCompat(intent) != null) {
startActivity(intent)
} else {
val packageName = intent.getPackage() ?: return
val marketUri = Uri.parse("market://details?id=$packageName")
val marketIntent = Intent(Intent.ACTION_VIEW, marketUri)
Timber.d("Trying to open market uri %s", marketUri)
if (packageManager.resolveActivityCompat(marketIntent) != null) {
startActivity(marketIntent)
try {
val intent = Intent.parseUri(url.toString(), flags)
if (packageManager.resolveActivityCompat(intent) != null) {
startActivity(intent)
} else {
val packageName = intent.getPackage() ?: return
val marketUri = Uri.parse("market://details?id=$packageName")
val marketIntent = Intent(Intent.ACTION_VIEW, marketUri)
Timber.d("Trying to open market uri %s", marketUri)
if (packageManager.resolveActivityCompat(marketIntent) != null) {
startActivity(marketIntent)
}
}
} catch (t: Throwable) {
Timber.w("Unable to parse intent uri: %s because: %s", url, t.message)
}
}

Expand Down

0 comments on commit 9a49a9f

Please sign in to comment.