public class DeviceApi extends BaseDeviceAtlasApi
The DeviceAtlas device detection API provides a way to detect devices based on the HTTP headers. Using these headers, the API returns device properties such as screen width, screen height, is mobile, vendor, model etc. If you want to use the DeviceAtlas API in a servlet container then it is strongly recommended to use DeviceApiWeb instead of this library.
The DeviceApiWeb is preferred when you want to perform real-time detection of a user's device in a servlet container.
The DeviceApi is preferred when you want to perform device outside of a servlet container or from an off-line User-Agent list or header set.
getProperties(Map<String, String> headers, String clientSide).
To get the most accurate results: 1- Pass all of the HTTP headers. 2- Use the DeviceAtlas Client-side component and pass the result.
When you have limited data you can also use these alternatives:
getProperties(Map<String, String> headers).
getProperties(String userAgent, String clientSide).
getProperties(String userAgent).
Map<String, String> headers = new HashMap<>(); headers.put("user-agent", "..."); headers.put("accept-language", "..."); // add any other available header... DeviceApi deviceApi = new DeviceApi(); try { DeviceApi.loadDataFromFile("/path/to/datafile.json"); // get all properties from the headers Properties props = DeviceApi.getProperties(headers); // .... use the properties .... if (props.contains("isMobilePhone", true)) { // it is a mobile phone } if (props.containsKey("model")) { String deviceModel = props.get("model").asString(); } if (props.containsKey("yearReleased")) { int deviceModel = props.get("yearReleased").asInteger(); } } catch (...) { ... }Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
API_VERSION |
Constructor and Description |
---|
DeviceApi()
Constructs a DeviceApi instance with default config.
|
DeviceApi(Config config)
Constructs a DeviceApi instance with custom config.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getApiVersion()
The version of this API.
|
java.lang.String |
getDataCreationIso8601()
The creation date/time of the loaded data file in ISO 8601 format.
|
java.lang.Integer |
getDataCreationTimestamp()
The creation date/time of the loaded data file as a Unix timestamp.
|
java.lang.String |
getDataVersion()
The version of the data file.
|
java.lang.String |
getDeviceAtlasApiVersion() |
Properties |
getProperties(java.util.Map<java.lang.String,java.lang.String> headers)
Get the properties for a map of HTTP headers.
|
Properties |
getProperties(java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String clientSideString)
Get the properties for a set of HTTP headers merged with properties from the
Client-side component.
|
Properties |
getProperties(java.lang.String identifier)
Get the properties for the provided identifier.
|
Properties |
getProperties(java.lang.String identifier,
java.lang.String clientSideString)
Get the properties for an identifier merged with the client side properties
(provided by the DeviceAtlas Client-side component).
|
java.util.Set<PropertyName> |
getPropertyNames()
Get a set of all possible property names.
|
void |
loadDataFromClassPath(java.lang.String fileName)
Load the DeviceAtlas device detection data into the API from a JSON file form the
class path.
|
void |
loadDataFromFile(java.lang.String jsonDataFilePath)
Load the DeviceAtlas device detection data into the API from a JSON file.
|
void |
loadDataFromStream(java.io.InputStream inputStream)
Load the DeviceAtlas device detection data into the API from an input stream.
|
downloadAndLoadDataFile, downloadAndLoadDataFile, getDetectionLookupCount, isDataFileReload, resetDetectionLookupCount
public static final java.lang.String API_VERSION
public DeviceApi()
Config
.Config
public DeviceApi(Config config)
config
- An instance of Config, you can change the DeviceAtlas API config
by creating an instance or Config and setting your custom config values and
then passing the instance to the DeviceApi constructor.Config
public void loadDataFromClassPath(java.lang.String fileName) throws DataLoadingException
fileName
- The JSON file-nameDataLoadingException
public void loadDataFromFile(java.lang.String jsonDataFilePath) throws DataLoadingException
jsonDataFilePath
- Path to the JSON fileDataLoadingException
public void loadDataFromStream(java.io.InputStream inputStream) throws DataLoadingException
inputStream
- Input streamDataLoadingException
public java.util.Set<PropertyName> getPropertyNames()
public static java.lang.String getApiVersion()
public java.lang.String getDataVersion()
public java.lang.Integer getDataCreationTimestamp()
public java.lang.String getDataCreationIso8601()
public Properties getProperties(java.lang.String identifier)
identifier
- The identifier string to identifypublic Properties getProperties(java.lang.String identifier, java.lang.String clientSideString) throws ClientPropertiesException
identifier
- An identifier such as a User-Agent or Client Hints model.clientSideString
- The contents of the cookie containing the client side propertiesClientPropertiesException
public Properties getProperties(java.util.Map<java.lang.String,java.lang.String> headers)
headers
- Client's request HTTP headerspublic Properties getProperties(java.util.Map<java.lang.String,java.lang.String> headers, java.lang.String clientSideString) throws ClientPropertiesException
headers
- Client's request HTTP headersclientSideString
- The contents of the cookie containing the client side propertiesClientPropertiesException
public java.lang.String getDeviceAtlasApiVersion()
Copyright © 2023 DeviceAtlas Limited. All rights reserved.