Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from jack-webb/better-url-intent.kt
Created September 13, 2023 13:04
Show Gist options
  • Save virendersran01/19edd5a5bbdec943694632832bfc5e63 to your computer and use it in GitHub Desktop.
Save virendersran01/19edd5a5bbdec943694632832bfc5e63 to your computer and use it in GitHub Desktop.
A better way to open a link in the user's browser
val url = Uri.parse("https://www.asos.com/")
val browserSelectorIntent = Intent()
  .setAction(Intent.ACTION_VIEW)
  .addCategory(Intent.CATEGORY_BROWSABLE)
  .setData(Uri.parse("http:"))
val targetIntent = Intent()
  .setAction(Intent.ACTION_VIEW)
  .addCategory(Intent.CATEGORY_BROWSABLE)
  .setData(url)
targetIntent.selector = browserSelectorIntent
startActivity(targetIntent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment