Skip to content

Instantly share code, notes, and snippets.

@ademirqueiroga
Created February 22, 2023 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademirqueiroga/5c28155af7d2fecd3245b37a4ea9da9f to your computer and use it in GitHub Desktop.
Save ademirqueiroga/5c28155af7d2fecd3245b37a4ea9da9f to your computer and use it in GitHub Desktop.
Handling channel/program intent
fun handleIntent(intent: Intent) {
val intentAction = intent.action
if (intentAction == Intent.ACTION_VIEW) {
val intentData = intent.data
val pathSegments = intentData?.pathSegments ?: emptyList()
when (pathSegments.firstOrNull()) {
"movie" -> pathSegments.get(1)?.let { movieId ->
val movie = MovieList.list.firstOrNull { it.id.toString() == movieId }
if (movie != null) {
val movieIntent = Intent(context, PlaybackActivity::class.java)
movieIntent.putExtra(PlaybackVideoFragment.MOVIE, movie)
startActivity(movieIntent)
}
}
"category" -> pathSegments.getOrNull(1)?.let { categoryId ->
selectRowForCategory(categoryId)
}
"discover", null -> {
// Just open the app. The user can browse content on the main screen
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment