# DeviceAtlas Device Detection for Apps #
The DeviceAtlas Device Detection API for Apps provides a way to detect devices based on
the make/model strings. Using the make and model information, the API returns device
information such as screen width, screen height, is mobile, vendor, model etc.
To see a full list of properties in DeviceAtlas please visit:
https://deviceatlas.com/resources/available-properties .
### Make-Model String Format ###
DeviceAtlas expects the make/model string in a specific format.
This format consists of values separated by a space character, where
the mandatory values are manufacturer and model. The string is the same for
all platforms:
```
"Make Model"
```
The term "Make" stands for manufacturer and the term "Model" stands for a
model number.
Modifications to the make or model strings obtained from the
device may result in non-identification or mis-identification.
#### Platform Specific Code (Make/Model) ####
The following code snippets detail how to obtain the make/model for the most
common mobile platforms. This or similar code needs be included in the mobile
application gathering the data to be passed to the DeviceAtlas API.
#### Android ####
Obtain the make/model string
```java
String make = android.os.Build.MANUFACTURER;
String model = android.os.Build.MODEL;
String makeModel = make + " " + model;
```
Make/model string examples from random devices
```
samsung SM-N9005
HTC HTC One mini 2
Meizu m2 note
OnePlus A0001
LGE Nexus 4
```
Note that the HTC example includes the "HTC" information twice.
That is because some devices are configured by the vendors to include
manufacturer information within the model (e.g. make = "HTC", model = "HTC One mini 2").
This is handled by the DeviceAtlas API, there is no need to manipulate the strings in advance.
#### iOS ####
Obtain the make/model string
```swift
NSString *make = @"Apple";
NSSString *model = [NSString stringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding];
NSString *makeModel = [make stringByAppendingString:model];
```
Make/model string examples from random devices
```
Apple iPhone7,1
Apple iPad3,4
```
For more information please visit:
https://deviceatlas.com/resources/getting-started-enterprise-for-apps
### Data File ###
The DeviceAtlas API relies on a device data file to function. DeviceAtlas
provides daily data file updates so it is recommended to download the data file
on a regular basis. This can be done manually from your account page or
automated via the https://deviceatlas.com/getJSON page.
For more information please see:
https://deviceatlas.com/resources/getting-the-data
### Dependencies ###
This library does not depend on any third party libraries.
### Library ###
The DeviceAtlas Device Identification API consists of two libraries and each
library has a separate jar file.
#### DeviceAtlas enterprise API (deviceatlas-enterprise-java-x.x.jar) ####
The main DeviceApi that loads the Device data and detects and returns the
properties for a set of request headers or the user-agent. Client-side
properties can be optionally passed to this library to get more accurate
results.
#### DeviceAtlas enterprise API Web (deviceatlas-enterprise-java-web-x.x.jar) ####
A small extension to the main API that allows passing of an HttpServletRequest
object for automatic extraction of the request headers and client-side
properties. Unless the HttpServletRequest object is not available or when
processing an off-line user-agent list or header set, it is strongly
recommended to use this library over the DeviceApi.
#### Basic Usage ####
The API can be used as follows:
To lookup the properties by passing the make/model string to the API:
```java
// the identification is done based on (HTTP headers) or user-agent string
/* (1) create an instance with default API configs and load the data file */
DeviceApi deviceApi = new DeviceApi();
try {
deviceApi.loadDataFromFile("/path/to/data-file.json");
} catch (Exception x) {
// handle the exceptions related to loading the data file
}
/* (2) or look up device properties by device make model string */
String makeModel = "samsung SM-N9005";
Properties properties = deviceApi.getProperties(userAgent);
/* (3) use the properties - e.g. detect mobile device */
// if there is a property named "mobileDevice" and the value is true
if (properties.contains("mobileDevice", true)) {
// example 1: Get the screen width for image optimization
int displayWidth = properties.containsKey("displayWidth")?
properties.get("displayWidth").asInteger(): 100;
// example 2: Get the device vendor name
String vendor = properties.containsKey("vendor")?
properties.get("vendor").asString(): "";
// example 3: Touch screen optimization
boolean useBiggerIcons = properties.contains("touchScreen", true);
// example 4: Send Geo Location JS to client?
boolean supportsGeoLocation = properties.contains("js.geoLocation", true);
}
```
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _
_ https://deviceatlas.com _