Created
July 27, 2015 10:52
-
-
Save twocity/77a8fee425cff40c27a9 to your computer and use it in GitHub Desktop.
getDefaultUserAgent
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
/** | |
* Returns an HTTP user agent of the form | |
* "Dalvik/1.1.0 (Linux; U; Android Eclair Build/MASTER)". | |
*/ | |
private static String getDefaultUserAgent() { | |
StringBuilder result = new StringBuilder(64); | |
result.append("Dalvik/"); | |
result.append(System.getProperty("java.vm.version")); // such as 1.1.0 | |
result.append(" (Linux; U; Android "); | |
String version = Build.VERSION.RELEASE; // "1.0" or "3.4b5" | |
result.append(version.length() > 0 ? version : "1.0"); | |
// add the model for the release build | |
if ("REL".equals(Build.VERSION.CODENAME)) { | |
String model = Build.MODEL; | |
if (model.length() > 0) { | |
result.append("; "); | |
result.append(model); | |
} | |
} | |
String id = Build.ID; // "MASTER" or "M4-rc20" | |
if (id.length() > 0) { | |
result.append(" Build/"); | |
result.append(id); | |
} | |
result.append(")"); | |
return result.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment