Last active
May 9, 2018 02:33
-
-
Save twiceyuan/86c7878cec0c05c39be610edc8a43414 to your computer and use it in GitHub Desktop.
[Intent Extras to String] 转换 Intent 的 Extras 为可读的 String #Android
This file contains hidden or 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
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("]"); | |
} |
This file contains hidden or 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.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