Search code examples
javabrowseruser-agent

Detect device types from user agent strings


I am trying to detect "desktop", "mobile", and "tablet" from user agent strings. What I need is just these three rough categories. Brand and device names are not needed. Some examples of user agent I have are:

"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)"

"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36"

Is there any existing API can do this?

According to the very last sentence of this article, it seems that looking for keyword "mobi" in a user agent string can handle most cases. But it seems too easy to be true......


Solution

  • You might use UADetector library that does just that. It has device categorization feature added since 0.9.10 version.

    UADetector is a library to identify over 190 different desktop and mobile browsers and 130 other User-Agents like feed readers, email clients and multimedia players. In addition, even more than 400 robots like BingBot, Googlebot or Yahoo Bot can be identified.