Skip to content

Instantly share code, notes, and snippets.

@googolmo

googolmo/API User-Agent

Last active Aug 29, 2015
Embed
What would you like to do?
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