Skip to content

Instantly share code, notes, and snippets.

@turastory
Created April 9, 2019 01:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turastory/30ef0de4108ea67e0ba24a03d681e0b7 to your computer and use it in GitHub Desktop.
Save turastory/30ef0de4108ea67e0ba24a03d681e0b7 to your computer and use it in GitHub Desktop.
Android deep link
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="test.com"
android:scheme="https" />
</intent-filter>
</activity>
private fun getPostIdFromIntent(): Int {
return intent.data
?.let { UrlQuerySanitizer(it.toString()) }
?.run {
// Path 1 - from deep link
val id = getValue("postId")
Log.e("asdf", "Get data from the url: $id")
id.toInt()
} ?: run {
// Path 2 - from internal activity
val id = intent.getIntExtra("postId", -1)
Log.e("asdf", "Get data from the activity: $id")
id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment