Skip to content

Instantly share code, notes, and snippets.

@googolmo
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save googolmo/643d93deb6b639ca776c to your computer and use it in GitHub Desktop.
Save googolmo/643d93deb6b639ca776c to your computer and use it in GitHub Desktop.
public static String generateUserAgent() {
StringBuilder builder = new StringBuilder("Android/");
builder.append(Build.VERSION.SDK_INT);
builder.append(" ");
builder.append(Build.BRAND.replace(" ", "_"));
builder.append("/");
builder.append(Build.MODEL.replace(" ", "_"));
builder.append(" ");
builder.append(Build.MANUFACTURER.replace(" ", "_"));
builder.append("/");
builder.append(Build.PRODUCT);
if (!TextUtils.isEmpty(BuildConfig.FLAVOR)) {
builder.append(" ");
builder.append(BuildConfig.FLAVOR.replace(" ", "_"));
}
builder.append(" ");
builder.append(BuildConfig.APPLICATION_ID);
builder.append("/");
builder.append(BuildConfig.VERSION_NAME);
builder.append("(");
builder.append(BuildConfig.VERSION_CODE);
builder.append(")");
return builder.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment