Skip to content

Instantly share code, notes, and snippets.

@jack-webb
Created June 1, 2023 10:44
Show Gist options
  • Save jack-webb/1170f75822514844005af693e914456b to your computer and use it in GitHub Desktop.
Save jack-webb/1170f75822514844005af693e914456b 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