UserAgentMetadata.Builder


public final class UserAgentMetadata.Builder


Builder used to create UserAgentMetadata objects.

Examples:

 // Create a setting with default options.
 new UserAgentMetadata.Builder().build();

      

// Create a setting with a brand version contains brand name: myBrand, major version: 100, // full version: 100.1.1.1. BrandVersion brandVersion = new BrandVersion.Builder().setBrand("myBrand") .setMajorVersion("100") .setFullVersion("100.1.1.1") .build(); new UserAgentMetadata.Builder().setBrandVersionList(Collections.singletonList(brandVersion)) .build();

// Create a setting brand version, platform, platform version and bitness. new UserAgentMetadata.Builder().setBrandVersionList(Collections.singletonList(brandVersion)) .setPlatform("myPlatform") .setPlatform("1.1.1.1") .setBitness(BITNESS_64) .build();

Summary

Public constructors

Create an empty UserAgentMetadata Builder.

Create a UserAgentMetadata Builder from an existing UserAgentMetadata object.

Public methods

@NonNull UserAgentMetadata

Builds the current settings into a UserAgentMetadata object.

@NonNull UserAgentMetadata.Builder

Sets the user-agent metadata architecture.

@NonNull UserAgentMetadata.Builder
setBitness(int bitness)

Sets the user-agent metadata bitness, the default value is BITNESS_DEFAULT, which indicates an empty string for sec-ch-ua-bitness.

@NonNull UserAgentMetadata.Builder

Sets user-agent metadata brands and their versions.

@NonNull UserAgentMetadata.Builder

Sets the user-agent metadata full version.

@NonNull UserAgentMetadata.Builder
setMobile(boolean mobile)

Sets the user-agent metadata mobile, the default value is true.

@NonNull UserAgentMetadata.Builder

Sets the user-agent metadata model.

@NonNull UserAgentMetadata.Builder

Sets the user-agent metadata platform.

@NonNull UserAgentMetadata.Builder

Sets the user-agent metadata platform version.

@NonNull UserAgentMetadata.Builder
setWow64(boolean wow64)

Sets the user-agent metadata wow64, the default is false.

Public constructors

Builder

Added in 1.9.0
public Builder()

Create an empty UserAgentMetadata Builder.

Builder

Added in 1.9.0
public Builder(@NonNull UserAgentMetadata uaMetadata)

Create a UserAgentMetadata Builder from an existing UserAgentMetadata object.

Public methods

build

Added in 1.9.0
public @NonNull UserAgentMetadata build()

Builds the current settings into a UserAgentMetadata object.

Returns
@NonNull UserAgentMetadata

The UserAgentMetadata object represented by this Builder

setArchitecture

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setArchitecture(@Nullable String architecture)

Sets the user-agent metadata architecture. If null is provided, the system default value will be used to generate the client hint.

Parameters
@Nullable String architecture

The architecture is used to generate user-agent client hint sec-ch-ua-arch.

setBitness

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setBitness(int bitness)

Sets the user-agent metadata bitness, the default value is BITNESS_DEFAULT, which indicates an empty string for sec-ch-ua-bitness.

Parameters
int bitness

The bitness is used to generate user-agent client hint sec-ch-ua-bitness.

setBrandVersionList

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setBrandVersionList(
    @NonNull List<UserAgentMetadata.BrandVersion> brandVersions
)

Sets user-agent metadata brands and their versions. The brand name, major version and full version should not be blank. The default value is an empty list which means the system default user-agent metadata brands and versions will be used to generate the user-agent client hints.

Parameters
@NonNull List<UserAgentMetadata.BrandVersion> brandVersions

a list of BrandVersion used to generated user-agent client hints sec-cu-ua and sec-ch-ua-full-version-list.

setFullVersion

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setFullVersion(@Nullable String fullVersion)

Sets the user-agent metadata full version. The full version should not be blank, even though the spec about brand full version could be empty. A blank full version could cause inconsistent brands when generating brand version related user-agent client hints. It also provides a bad experience for developers when processing the brand full version. If null is provided, the system default value will be used to generate the client hint.

Parameters
@Nullable String fullVersion

The full version is used to generate user-agent client hint sec-ch-ua-full-version.

setMobile

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setMobile(boolean mobile)

Sets the user-agent metadata mobile, the default value is true.

Parameters
boolean mobile

The mobile is used to generate user-agent client hint sec-ch-ua-mobile.

setModel

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setModel(@Nullable String model)

Sets the user-agent metadata model. If null is provided, the system default value will be used to generate the client hint.

Parameters
@Nullable String model

The model is used to generate user-agent client hint sec-ch-ua-model.

setPlatform

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setPlatform(@Nullable String platform)

Sets the user-agent metadata platform. The platform should not be blank. If null is provided, the system default value will be used to generate the client hint.

Parameters
@Nullable String platform

The platform is used to generate user-agent client hint sec-ch-ua-platform.

setPlatformVersion

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setPlatformVersion(@Nullable String platformVersion)

Sets the user-agent metadata platform version. If null is provided, the system default value will be used to generate the client hint.

Parameters
@Nullable String platformVersion

The platform version is used to generate user-agent client hint sec-ch-ua-platform-version.

setWow64

Added in 1.9.0
public @NonNull UserAgentMetadata.Builder setWow64(boolean wow64)

Sets the user-agent metadata wow64, the default is false.

Parameters
boolean wow64

The wow64 is used to generate user-agent client hint sec-ch-ua-wow64.