public class MatchForDeviceId extends Object
Example illustrates:
provider = new Provider(StreamFactory.create
(Shared.getLitePatternV32(), false));
provider.match(mobileUserAgent);
Match matchFromUA;
as a string:
matchFromUA.getDeviceId();
as byte array:
matchFromUA.getDeviceIdAsByteArray();
as list of profile IDs:
for (Profile profile : matchFromUA.getProfiles()) {
device.matchForDeviceIdArray(deviceIdByteArray);
device.matchForDeviceIdString(deviceIdString);
device.matchForDeviceIdList(deviceIdList);
At the end a short console message will be printed containing a hash code of the object, deviceId and the value for the IsMobile property. Notice that all three objects are different as demonstrated by hash value but have the same deviceId and value for the IsMobile property.
Storing deviceId as opposed to the individual properties is a much more efficient way of retaining device information for future use. Byte array is the most efficient of the three options demonstrated as it only requires enough space to store the number of integers corresponding to the number of profiles (one profile per component).
main assumes it is being run with a working directory at root of project or of this module.
| Modifier and Type | Field and Description |
|---|---|
protected String |
mobileUserAgent |
protected Provider |
provider |
| Constructor and Description |
|---|
MatchForDeviceId()
Creates new provider object with the Stream dataset.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the
Dataset by releasing data
file readers and freeing the data file from locks. |
static void |
main(String[] args)
Performs a match of the pre-defined User-Agent to retrieve Id, then
shows how to use the Id to get a Match object.
|
Match |
matchForDeviceIdArray(byte[] deviceId)
Returns a Match object corresponding to the provided byte array Id.
|
Match |
matchForDeviceIdList(ArrayList<Integer> deviceIds)
Returns a Match object corresponding to the provided list of profile IDs.
|
Match |
matchForDeviceIdString(String deviceId)
Returns a Match object corresponding to the provided string deviceId.
|
Match |
matchForUserAgent(String userAgent)
Performs match for a User-Agent string and returns Match object with
detection results.
|
protected final Provider provider
protected final String mobileUserAgent
public MatchForDeviceId()
throws IOException
IOException - if there was a problem accessing the data file.public static void main(String[] args) throws IOException
Three match objects with different references but same deviceId and IsMobile values are generated to demonstrate that all three methods of storing deviceId produce the same result.
args - command line arguments.IOException - if there was a problem accessing data file.public Match matchForUserAgent(String userAgent) throws IOException
userAgent - String representing typical HTTP User-Agent header.IOException - if there was a problem accessing the data file.public Match matchForDeviceIdString(String deviceId) throws IOException
match.getDeviceId();deviceId - String representation of the deviceId.IOException - if there was a problem accessing the data file.public Match matchForDeviceIdArray(byte[] deviceId) throws IOException
match.getDeviceIdAsByteArray();deviceId - byte array representation of deviceId.IOException - if there was a problem accessing the data file.public Match matchForDeviceIdList(ArrayList<Integer> deviceIds) throws IOException
for (Profile profile : match.getProfiles()) {deviceIds - a list of integers where each integer is a profile Id.IOException - if there was a problem accessing the data file.public void close()
throws IOException
Dataset by releasing data
file readers and freeing the data file from locks. This method should
only be used when the Dataset is no longer required, i.e. when
device detection functionality is no longer required, or the data file
needs to be freed.IOException - if there is a problem accessing the data file.Copyright © 2018 51Degrees. All rights reserved.