Package com.castlabs.android.network
Class UserAgent
java.lang.Object
com.castlabs.android.network.UserAgent
Instances of this class are used to construct the user agent that is used for HTTP requests.
Additional key/value properties can be registered using
register(String, String)
.
Since version 4.0.1 this class strips non-ASCII characters from the User-Agent by default.
You can disable this behaviour by setting STRIP_NON_ASCII_CHARACTERS
to false
Default fields can also be enabled or disabled through the setFields(int)
method.- Since:
- 3.0.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
The flags that enable or disable field presence in the User-Agent. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Flag to include the Android API level in the user-agent.static final int
Flag to include the device ID in the user-agent.static final int
Flag to include the Exoplayer version in the user-agent.static final int
Flag to include the device model in the user-agent.static boolean
By default, the UserAgent string will be stripped and all non-ASCII characters will be removed. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
disableFields
(int fields) Disable user-agent fieldsstatic void
enableFields
(int fields) Enable user-agent fieldsstatic int
Returns the currently enabled fields to include in the user-agentstatic void
Register an additional key value pair that will be added to the user agent string representationstatic void
setFields
(int enabledFields) Sets the currently enabled fields to include in the user-agent.static void
setOverrideValue
(String overrideValue) Sets the over-ride value for the user-agent, if it is not null all other values would be ignored and this value would be used for the user-agent.static void
Sets the prefix for the user-agent, if it is null the CastLabs SDK version would be considered as the prefix.toString()
-
Field Details
-
STRIP_NON_ASCII_CHARACTERS
public static boolean STRIP_NON_ASCII_CHARACTERSBy default, the UserAgent string will be stripped and all non-ASCII characters will be removed. You can set this flag totrue
to disable the filter. Please note that some HTTP stacks, especially the one used by OkHttp do not allow non-ASCII characters in the User Agent and you will get an Exception if you change the behaviour.- Since:
- 4.0.1
-
FLAG_ENABLE_MODEL
public static final int FLAG_ENABLE_MODELFlag to include the device model in the user-agent.- See Also:
-
FLAG_ENABLE_API_LEVEL
public static final int FLAG_ENABLE_API_LEVELFlag to include the Android API level in the user-agent.- See Also:
-
FLAG_ENABLE_EXO_VERSION
public static final int FLAG_ENABLE_EXO_VERSIONFlag to include the Exoplayer version in the user-agent.- See Also:
-
FLAG_ENABLE_DEVICE_ID
public static final int FLAG_ENABLE_DEVICE_IDFlag to include the device ID in the user-agent. Due to privacy reasons this is omitted by default. You can still enable it manually by adding it to thesetFields(int)
- See Also:
-
-
Constructor Details
-
UserAgent
public UserAgent()
-
-
Method Details
-
register
Register an additional key value pair that will be added to the user agent string representation- Parameters:
key
- the keyvalue
- the value
-
setFields
Sets the currently enabled fields to include in the user-agent.- Parameters:
enabledFields
- fields to enable
-
enableFields
Enable user-agent fields- Parameters:
fields
- the uset-agent fields to enable
-
disableFields
Disable user-agent fields- Parameters:
fields
- the uset-agent fields to disable
-
getEnabledFields
public static int getEnabledFields()Returns the currently enabled fields to include in the user-agent- Returns:
- the currently enabled fields to include in the user-agent
-
toString
-
setPrefix
Sets the prefix for the user-agent, if it is null the CastLabs SDK version would be considered as the prefix.- Parameters:
prefix
- The prefix
-
setOverrideValue
Sets the over-ride value for the user-agent, if it is not null all other values would be ignored and this value would be used for the user-agent.- Parameters:
overrideValue
- The over-ride value
-