Created
July 12, 2021 12:58
-
-
Save abhishekgargx/1976b27b93abc0622b1889bafee4fea1 to your computer and use it in GitHub Desktop.
Convert intent to 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 convertIntentToString(Intent intent){ | |
try{ | |
if (intent == null || intent.getExtras() == null){ | |
return null; | |
} | |
StringBuilder data = new StringBuilder(); | |
data.append("#\n").append("intent : --->>").append(intent.toString()); | |
Set<String> extraSet = intent.getExtras().keySet(); | |
data.append("Extra ---------\n"); | |
for (String key: extraSet) { | |
data.append("\n") | |
.append(key) | |
.append(":"); | |
Object extraData = intent.getExtras().get(key); | |
if (!(extraData instanceof String)){ | |
data.append(new Gson().toJson(extraData)); | |
}else{ | |
data.append(String.valueOf(intent.getExtras().get(key))); | |
} | |
} | |
if(intent.getDataString() != null){ | |
data.append("#\n").append("DataString : --->>").append(intent.getDataString()); | |
} | |
if (intent.getAction() != null){ | |
data.append("#\n").append("Action : --->>").append(intent.getAction()); | |
} | |
return data.toString(); | |
}catch (Exception e){ | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment