All Projects → mngsk → device-detector

mngsk / device-detector

Licence: LGPL-3.0 license
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to device-detector

ember-useragent
An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.
Stars: ✭ 34 (-30.61%)
Mutual labels:  browser-detection, device-detector
Ua Parser Js
UAParser.js - Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data. Supports browser & node.js environment.
Stars: ✭ 6,421 (+13004.08%)
Mutual labels:  browser-detection, os-detection
Bowser
a browser detector
Stars: ✭ 5,006 (+10116.33%)
Mutual labels:  browser-detection, os-detection
concorde.js
A sexy pinnacle of engineering that’s nonetheless incredibly inefficient and expensive and goes out of business because it can’t find enough use. It also provides some tools to deal with the browser.
Stars: ✭ 17 (-65.31%)
Mutual labels:  browser-detection
udger-java
Java agent string parser based on Udger https://udger.com/products/local_parser
Stars: ✭ 24 (-51.02%)
Mutual labels:  device-detector
LBFH
About All in one tool for Information Gathering, Vulnerability Scanning and Crawling. A must have tool for all penetration testers
Stars: ✭ 46 (-6.12%)
Mutual labels:  os-detection
Browser
Do some browser detection with Ruby. Includes ActionController integration.
Stars: ✭ 2,263 (+4518.37%)
Mutual labels:  browser-detection
Device Detector
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Stars: ✭ 2,106 (+4197.96%)
Mutual labels:  device-detector
Deviice
Swift library to easily check the current device and some more info about it.
Stars: ✭ 51 (+4.08%)
Mutual labels:  device-detector
udger-python
Python agent string parser based on Udger https://udger.com/products/local_parser
Stars: ✭ 34 (-30.61%)
Mutual labels:  device-detector

Device Detector

build release maven central license

The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models.

This project is a Java adaptation of Matomo Device Detector.

Usage

Using DeviceDetector with Maven is quite easy. Just add the following dependency in your project's pom.xml:

<dependency>
	<groupId>io.github.mngsk</groupId>
	<artifactId>device-detector</artifactId>
	<version>1.0.10</version>
</dependency>

And use some code like this one:

import io.github.mngsk.devicedetector.DeviceDetector;
import io.github.mngsk.devicedetector.DeviceDetector.DeviceDetectorBuilder;

DeviceDetector dd = new DeviceDetectorBuilder().build();

// Assuming `request` is an instance of HttServletRequest
String userAgent = request.getHeader("User-Agent");

Detection detection = dd.detect(userAgent);
System.out.println(detection.getDevice().map(d -> d.toString()).orElse("unknown"));
System.out.println(detection.getOperatingSystem().map(d -> d.toString()).orElse("unknown"));
System.out.println(detection.getClient().map(d -> d.toString()).orElse("unknown"));

if (detection.getDevice().isPresent()) {
	System.out.println(detection.getDevice().get().getType()); // bot, browser, feed reader...
	System.out.println(detection.getDevice().get().getBrand().orElse("unknown"));
	System.out.println(detection.getDevice().get().getModel().orElse("unknown"));
}

Instead of using the full power of DeviceDetector it might in some cases be better to use only specific parsers. If you aim to check if a given user agent is a bot and don't require any of the other information, you can enable only the bot parser.

import io.github.mngsk.devicedetector.DeviceDetector;
import io.github.mngsk.devicedetector.DeviceDetector.DeviceDetectorBuilder;

DeviceDetector dd = new DeviceDetectorBuilder().disableEverything().enableBots().build();

Detection detection = dd.detect(userAgent);

if (detection.isBot()) {
	System.out.println(detection.getClient().get().getName().get());
}

Caching

Contrary to the original PHP implementation, this project does not include any caching mechanism. Consider using an specialized tool for that purpose.

Contributing

Please note that we use the fixture files directly from the original PHP project; if you want to contribute or fix a regex, please consider making a pull request on that project, so that all derivative projects -including this one- can benefit from it.

On the other hand, contributions of java code are very welcome.

Tests

This project uses the YAML fixture files of the original PHP version. To run the tests, execute mvn test from the project's root directory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].