Skip to content

Instantly share code, notes, and snippets.

@twiceyuan
Last active May 9, 2018 02:33
Show Gist options
  • Save twiceyuan/86c7878cec0c05c39be610edc8a43414 to your computer and use it in GitHub Desktop.
Save twiceyuan/86c7878cec0c05c39be610edc8a43414 to your computer and use it in GitHub Desktop.
[Intent Extras to String] 转换 Intent 的 Extras 为可读的 String #Android
public static String toExtrasString(Intent intent) {
Bundle extras = intent.getExtras();
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append("[");
List<String> keyList = new ArrayList<>(extras.keySet());
for (int i = 0;i < keyList.size();i++) {
String key = key.get(i);
resultBuilder.append(key + "=" + extras.get(key));
if (i != keyList.size() - 1) {
resultBuilder.append(", ");
}
}
resultBuilder.append("]");
}
fun Intent.toExtrasString(): String = "[${extras?.keySet()?.joinToString(", ") { "$it=${extras.get(it)}" }}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment