# DeviceAtlas Device Detection for Apps # The DeviceAtlas Device Detection API for Apps provides a way to detect devices based on 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. It is important to pass the string to the DeviceAtlas API in the lowercase form when using lowercased data file. Other modifications to the make or model strings obtained from the device may result in non-identification or mis-identification. 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 in an automated way 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 API is a single package that contains a single module for the Device Detection API. #### DeviceApi #### The main library that loads the Device data and detects and returns the properties for a set of request headers or a user-agent. Client-side properties can be optionally passed to this library to get more accurate results. ### Basic Usage ### The API can be used as follows: To lookup the properties by passing the make/model string to the API: ```c #include <dac.h> // The 2 functions below are necessary for da_atlas_compile // as it needs 2 function pointers for reading and seeking in the data file static size_t filereader(void *ctx, size_t count, char *buf) { return fread(buf, 1, count, ctx); } static da_status_t fileseeker(void *ctx, off_t pos) { return fseek(ctx, pos, SEEK_SET) != -1 ? DA_OK : DA_SYS; } ... da_atlas_t atlas; da_status_t status; void *ptr; size_t size; const char *jsonpath = argv[1]; ... // Json file reading FILE *json = fopen(jsonpath, "r"); if (!json) { fprintf(stderr, "fread failed: %s\n", jsonpath); exit(EXIT_FAILURE); } da_init(); if ((status = da_atlas_compile(json, filereader, fileseeker, &ptr, &size)) != DA_OK) { fprintf(stderr, "da_atlas_compile failed\n"); goto dafini; } da_property_decl_t extraprops[] = {{ 0, 0 }}; if ((status = da_atlas_open(&atlas, extraprops, ptr, size)) != DA_OK) { fprintf(stderr, "da_atlas_open failed\n"); goto daclose; } const char *makemodel = "samsung SM-N9005"; da_evidence_id_t mainid = da_atlas_evidence_id(&atlas, "user-agent"); da_evidence_t headers[] = {{ mainid, makemodel }}; da_deviceinfo_t device; if ((status = da_searchv(&atlas, &device, headers, 1)) != DA_OK) { fprintf(stderr, "da_search failed\n"); goto daclose; } da_propid_t *mprop; da_propid_t *dprop; da_propid_t *vprop; da_propid_t *jprop; da_propid_t *tprop; bool mobiledevice; bool touchscreen; bool jsgetlocation; long displaywidth; const char *vendor; da_atlas_getpropid(&atlas, "mobileDevice", mprop); da_atlas_getpropid(&atlas, "touchScreen", tprop); da_atlas_getpropid(&atlas, "js.geoLocation", jprop); da_atlas_getpropid(&atlas, "displayWidth", dprop); da_atlas_getpropid(&atlas, "vendor", vprop); if (da_getpropboolean(&device, *mprop, &mobiledevice) != DA_OK) mobiledevice = false; if (da_getpropboolean(&device, *tprop, &touchscreen) != DA_OK) touchscreen = false; if (da_getpropboolean(&device, *jprop, &jsgeolocation) != DA_OK) jsgeolocation = false; if (da_getpropinteger(&device, *dprop, &displaywidth) != DA_OK) displaywidth = = 100; if (da_getpropstring(&device, *vprop, &vendor) != DA_OK) vendor = ""; da_close(&device); daclose: da_atlas_close(&atlas); free(ptr); dafini: da_fini(); ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _ _ https://deviceatlas.com _ <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Main</a></li><li class="divider"></li><li><a href="README.DeviceApi-Web.html">Device Detection for Web</a></li><li class="disabled"><a href="README.DeviceApi-Apps.html">Device Detection for Apps</a></li><li><a href="README.DeviceApi-Config.html">Device Detection API Config</a></li><li><a href="README.CarrierApi.html">Carrier Identification API</a></li><li class="divider"></li><li><a href="README.Unix.html">C API and Unix</a></li><li><a href="README.Windows.html">C API and Windows</a></li><li class="divider"></li><li><a href="README.Nginx.html">C API and NGINX Module Installation</a></li><li class="divider"></li><li><a href="README.JsonConverter.html">C API JSONConverter</a></li><li><a href="https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html" target="_blank">Client-side Component</a></li><li><a href="README.ConnectivityAnalyser-Nginx.html">NGINX DeviceAtlas Connectivity Analyser</a></li><li><a href="README.ConnectivityAnalyser-Apache.html">Apache DeviceAtlas Connectivity Analyser</a></li><li><a href="ApiDocs/index.html">DeviceAtlas ApiDocs</a></li></ul></div>