Skip to content

Instantly share code, notes, and snippets.

@frogggias
Last active October 18, 2022 22:11
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 frogggias/a40d6eeb7e242b22ea84b5e46d76a681 to your computer and use it in GitHub Desktop.
Save frogggias/a40d6eeb7e242b22ea84b5e46d76a681 to your computer and use it in GitHub Desktop.
Kotlin extension for pretty print of Android Intent
fun Intent.prettyPrint(): String = buildString {
append("Intent {")
val values = listOf<Pair<String, String?>>(
"action" to action,
"data" to data.toString(),
"type" to type,
"component" to component?.flattenToString(),
"flags" to flags.toString(),
"package" to `package`,
"categories" to categories?.joinToString(","),
"extras" to extras?.let { extras ->
extras.keySet().joinToString(",") { key -> "$key=${extras.get(key)}" }
},
)
values
.filter { (_, value) -> value != null }
.forEach { (key, value) ->
append(" $key=$value")
append('\n')
}
append("}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment