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 |
|---|
Builder()Create an empty UserAgentMetadata Builder. |
Builder(@NonNull UserAgentMetadata uaMetadata)Create a UserAgentMetadata Builder from an existing UserAgentMetadata object. |
Public methods |
|
|---|---|
@NonNull UserAgentMetadata |
build()Builds the current settings into a UserAgentMetadata object. |
@NonNull UserAgentMetadata.Builder |
setArchitecture(@Nullable String architecture)Sets the user-agent metadata architecture. |
@NonNull UserAgentMetadata.Builder |
setBitness(int bitness)Sets the user-agent metadata bitness, the default value is |
@NonNull UserAgentMetadata.Builder |
setBrandVersionList(Sets user-agent metadata brands and their versions. |
@NonNull UserAgentMetadata.Builder |
@RequiresFeature(name = WebViewFeature.USER_AGENT_METADATA_FORM_FACTORS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets the user-agent metadata form factors. |
@NonNull UserAgentMetadata.Builder |
setFullVersion(@Nullable String fullVersion)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 |
setPlatform(@Nullable String platform)Sets the user-agent metadata platform. |
@NonNull UserAgentMetadata.Builder |
setPlatformVersion(@Nullable String platformVersion)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
public Builder(@NonNull UserAgentMetadata uaMetadata)
Create a UserAgentMetadata Builder from an existing UserAgentMetadata object.
Public methods
build
public @NonNull UserAgentMetadata build()
Builds the current settings into a UserAgentMetadata object.
| Returns | |
|---|---|
@NonNull UserAgentMetadata |
The UserAgentMetadata object represented by this Builder |
setArchitecture
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.
setBitness
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 |
setBrandVersionList
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 |
setFormFactors
@RequiresFeature(name = WebViewFeature.USER_AGENT_METADATA_FORM_FACTORS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @NonNull UserAgentMetadata.Builder setFormFactors(@NonNull List<String> formFactors)
Sets the user-agent metadata form factors. The default value is an empty list which means the system default user-agent metadata form factor will be used to generate the user-agent client hints. Form factor value should be one or more of FORM_FACTOR_DESKTOP, FORM_FACTOR_AUTOMOTIVE, FORM_FACTOR_MOBILE, FORM_FACTOR_TABLET, FORM_FACTOR_XR, FORM_FACTOR_EINK, FORM_FACTOR_WATCH. See the spec for more details.
| Parameters | |
|---|---|
@NonNull List<String> formFactors |
The form factors is used to generate user-agent client hint |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the list contains an invalid form factor string. |
java.lang.UnsupportedOperationException |
if the |
setFullVersion
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.
setMobile
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 |
setModel
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.
setPlatform
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.
setPlatformVersion
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.
setWow64
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 |