Skip to content

Instantly share code, notes, and snippets.

@Oleur
Created June 2, 2021 19:37
Show Gist options
  • Save Oleur/6bd403925ea3378d4c2ae8edfcfb85b2 to your computer and use it in GitHub Desktop.
Save Oleur/6bd403925ea3378d4c2ae8edfcfb85b2 to your computer and use it in GitHub Desktop.
Handle deeplink
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent.handleIntent()
}
}
private fun Intent.handleIntent() {
when (action) {
Intent.ACTION_VIEW -> controller.handleDeepLink(data)
}
}
private fun handleDeepLink(data: Uri?) {
when (data?.path) {
"/call-number" -> {
val number = data.getQueryParameter("telephone").orEmpty()
// Navigate to dialer with the number
}
"/call-name" -> {
val name = data.getQueryParameter("name").orEmpty()
// Navigate to home screen and search for the contact and call
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment