Created
April 9, 2019 01:30
-
-
Save turastory/30ef0de4108ea67e0ba24a03d681e0b7 to your computer and use it in GitHub Desktop.
Android deep link
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
<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> |
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
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