What's Covered
51Degrees device detector returns all detection results as a string. This tutorial demonstrates how to return results for the IsMobile property value as a boolean.
Code and Explanation
Strongly Typed example of using 51Degrees device detection. The example shows how to:
-
Load the 51Degrees Hash Trie library
res = FiftyOneDegreesTrieV3.class.getResource("/FiftyOneDegreesTrieV3.so"); System.load(res.getPath());
-
Instantiate 51Degrees detection provider
provider = new Provider("path/to/51Degrees/data/file.trie");
-
Pass in a single HTTP User-Agent header
Match match = provider.match(userAgent);
-
Extract the value of the IsMobile property as boolean
Boolean.parseBoolean(match.getValue("IsMobile"));
Summary
In this tutorial you have seen how to use the detector to retrieve the IsMobile property for a pre-defined User-Agent string. It sets a boolean value to true or false from the original string value of "True" or "False", making if statements simpler to test.