Created
June 2, 2021 19:37
-
-
Save Oleur/6bd403925ea3378d4c2ae8edfcfb85b2 to your computer and use it in GitHub Desktop.
Handle deeplink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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