Last active
October 18, 2022 22:11
-
-
Save frogggias/a40d6eeb7e242b22ea84b5e46d76a681 to your computer and use it in GitHub Desktop.
Kotlin extension for pretty print of Android Intent
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
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