Skip to content

Instantly share code, notes, and snippets.

@SergeiMikhailovskii
Created March 23, 2024 15:34
Show Gist options
  • Save SergeiMikhailovskii/4e96a54d5ba2e06edbd421a94cbcb6e5 to your computer and use it in GitHub Desktop.
Save SergeiMikhailovskii/4e96a54d5ba2e06edbd421a94cbcb6e5 to your computer and use it in GitHub Desktop.
fun Context.openMarket(deeplink: String, url: String) {
val marketAppIntent = Intent(Intent.ACTION_VIEW, Uri.parse(deeplink)).apply {
flags += Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK
}
val marketInBrowserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
runCatching {
startActivity(marketAppIntent)
}.getOrElse {
startActivity(marketInBrowserIntent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment