Package com.castlabs.android.network
Class UserAgent
- java.lang.Object
-
- com.castlabs.android.network.UserAgent
-
public class UserAgent extends Object
Instances of this class are used to construct the user agent that is used for HTTP requests. Additional key/value properties can be registered usingregister(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 settingSTRIP_NON_ASCII_CHARACTERSto false Default fields can also be enabled or disabled through thesetFields(int)method.- Since:
- 3.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceUserAgent.UserAgentFlagsThe flags that enable or disable field presence in the User-Agent.
-
Field Summary
Fields Modifier and Type Field Description static intFLAG_ENABLE_API_LEVELFlag to include the Android API level in the user-agent.static intFLAG_ENABLE_DEVICE_IDFlag to include the device ID in the user-agent.static intFLAG_ENABLE_EXO_VERSIONFlag to include the Exoplayer version in the user-agent.static intFLAG_ENABLE_MODELFlag to include the device model in the user-agent.static booleanSTRIP_NON_ASCII_CHARACTERSBy default, the UserAgent string will be stripped and all non-ASCII characters will be removed.
-
Constructor Summary
Constructors Constructor Description UserAgent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voiddisableFields(int fields)Disable user-agent fieldsstatic voidenableFields(int fields)Enable user-agent fieldsstatic intgetEnabledFields()Returns the currently enabled fields to include in the user-agentstatic voidregister(String key, String value)Register 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.StringtoString()
-
-
-
Field Detail
-
STRIP_NON_ASCII_CHARACTERS
public static boolean STRIP_NON_ASCII_CHARACTERS
By 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_MODEL
Flag to include the device model in the user-agent.- See Also:
- Constant Field Values
-
FLAG_ENABLE_API_LEVEL
public static final int FLAG_ENABLE_API_LEVEL
Flag to include the Android API level in the user-agent.- See Also:
- Constant Field Values
-
FLAG_ENABLE_EXO_VERSION
public static final int FLAG_ENABLE_EXO_VERSION
Flag to include the Exoplayer version in the user-agent.- See Also:
- Constant Field Values
-
FLAG_ENABLE_DEVICE_ID
public static final int FLAG_ENABLE_DEVICE_ID
Flag 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:
- Constant Field Values
-
-
Method Detail
-
register
public static void register(@NonNull String key, @NonNull String value)Register an additional key value pair that will be added to the user agent string representation- Parameters:
key- the keyvalue- the value
-
setFields
public static void setFields(@UserAgentFlags int enabledFields)
Sets the currently enabled fields to include in the user-agent.- Parameters:
enabledFields- fields to enable
-
enableFields
public static void enableFields(@UserAgentFlags int fields)
Enable user-agent fields- Parameters:
fields- the uset-agent fields to enable
-
disableFields
public static void disableFields(@UserAgentFlags int fields)
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
-
-