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).

Example usage:

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.

Author

DeviceAtlas Limited

Hierarchy

  • DeviceApi

Constructors

  • Parameters

    • Optional config: Config

    Returns DeviceApi

Properties

clientSideParser: ClientSideParser
componentDetector: ComponentDetector
config: Config = null
deviceData: DeviceData
hasNoMakeModelInputIdentifier: boolean = false
hasOnlyMakeModelInputIdentifier: boolean = false
httpInputSanitiser: InputSanitiser
internalDataFileBasedlookupMethodHelper: any = null
lookupCache: LRUCache<string, Properties> = null
propertiesCollector: PropertiesCollector
propertyMappingsRunner: PropertyMappingsRunner
ACCEPT_LANGUAGE_HEADER: string = "accept-language"
API_VERSION: string = "3.2.1"
XMSG_FILE_NOT_FOUND: string = "File \"{0}\" not found."
XMSG_FILE_NOT_FOUND_ON_CLASS_PATH: string = "File \"{0}\" not found on classpath."
XMSG_MISSING_DATA: string = "The device instance failed to initialize: data file should be loaded first"
XMSG_PROBLEM_READING_FROM_STREAM: string = "Problem reading JSON data from stream."

Methods

  • Parameters

    • dynamicProperties: HashMap<string, Property>
    • headers: HashMap<string, string>

    Returns void

  • Parameters

    • identifier: string

    Returns {
        make-model: string;
    }

    • make-model: string
  • Returns void

  • Parameters

    • headers: HashMap<string, string>
    • clientSideString: string

    Returns Properties

  • Parameters

    Returns void

  • Parameters

    • headers: HashMap<string, string>

    Returns string

  • Parameters

    • headers: HashMap<String, String>
    • clientSideString: string
    • acceptLanguage: string

    Returns string

  • Parameters

    • request: any

    Returns string

  • The creation date/time of the loaded data file in ISO 8601 format.

    Returns

    The creation date/time of the loaded data file in ISO 8601 format.

    Returns string

  • The creation date/time of the loaded data file as a Unix timestamp.

    Returns

    The creation date/time of this data file as a Unix timestamp.

    Returns number

  • The version of the data file.

    Returns

    The device data file version.

    Returns string

  • Get the properties for the provided identifier. The identifier may be a User-Agent string, Client Hints model or if enabled in the data file an app "Make Model" string.

    Returns

    A collection of properties (Property objects) wrapped in a Properties object

    Parameters

    • identifier: string | object = ''
    • clientSideString: string = ''

    Returns Properties

  • Get the properties for a request. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values for all usable headers.

    Returns

    A set of properties (Property objects) wrapped in a Properties object

    Parameters

    • request: any

    Returns Properties

  • Parameters

    • headers: object
    • clientSideString: string

    Returns Properties

  • Get a set of all possible property names. Note that the client side properties are not included in this set.

    Returns

    A set of all possible device property names as PropertyName objects.

    Returns HashSet<PropertyName>

  • Load the DeviceAtlas device detection data into the API from an input stream.

    Throws

    Exception for reading JSON data from stream.

    Parameters

    • jsonStr: string

    Returns void

  • Load the DeviceAtlas device detection data into the API from a JSON file. The JSON data file is provided by the DeviceAtlas website.

    Parameters

    • jsonStr: string

    Returns void

  • Parameters

    • headers: object

    Returns HashMap<string, string>

  • Parameters

    • cookieString: string = ''

    Returns object

  • Parameters

    • identifier: string

    Returns {
        make-model: string;
        user-agent: string;
    }

    • make-model: string
    • user-agent: string
  • Parameters

    • identifier: string

    Returns {
        user-agent: string;
    }

    • user-agent: string
  • The version of this API.

    Returns

    DeviceApi version

    Returns string

Generated using TypeDoc