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
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceThe flags that enable or disable field presence in the User-Agent. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFlag to include the Android API level in the user-agent.static final intFlag to include the device ID in the user-agent.static final intFlag to include the Exoplayer version in the user-agent.static final intFlag to include the device model in the user-agent.static booleanBy default, the UserAgent string will be stripped and all non-ASCII characters will be removed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddisableFields(int fields) Disable user-agent fieldsstatic voidenableFields(int fields) Enable user-agent fieldsstatic intReturns the currently enabled fields to include in the user-agentstatic voidRegister an additional key value pair that will be added to the user agent string representationstatic voidsetFields(int enabledFields) Sets the currently enabled fields to include in the user-agent.static voidsetOverrideValue(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 voidSets 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 totrueto 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()Default constructor for 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
-