User Agent Parser
DetectDevice Method
Example 



KellermanSoftware.UserAgentParser Namespace > DetectionLogic Class : DetectDevice Method
The user agent string
Detects the device from a user agent string
Syntax
'Declaration
 
Public Function DetectDevice( _
   ByVal userAgent As String _
) As DeviceInformation
'Usage
 
Dim instance As DetectionLogic
Dim userAgent As String
Dim value As DeviceInformation
 
value = instance.DetectDevice(userAgent)
public DeviceInformation DetectDevice( 
   string userAgent
)
public:
DeviceInformation^ DetectDevice( 
   String^ userAgent
) 

Parameters

userAgent
The user agent string

Return Value

DeviceInformation
Exceptions
ExceptionDescription
userAgent
Example
DetectionLogic detectionLogic = new DetectionLogic(); //Trial Mode
//DetectionLogic detectionLogic = new DetectionLogic("place user name here", "place license key here"); //License Mode
 
//Parameters
string userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25";
 
DeviceInformation info = detectionLogic.DetectDevice(userAgent);
 
//Write out everything at once
Console.WriteLine(info.ToString());
 
//Write out individual properties
Console.WriteLine(info.UserAgent);
Console.WriteLine(info.EasyBrowser);
Console.WriteLine(info.EasyPlatform);
Console.WriteLine(info.BrowserType);
Console.WriteLine(info.IsTouch);
Console.WriteLine(info.BrowserName);
Console.WriteLine(info.BrowserVersion);
Console.WriteLine(info.BrandName);
Console.WriteLine(info.Identifier);
Console.WriteLine(info.ModelName);
Console.WriteLine(info.ModelNumber);
Console.WriteLine(info.OperatingSystem);
Console.WriteLine(info.OperatingSystemVersion);
Console.WriteLine(info.ProcessorType);
Console.WriteLine(info.Culture);
Console.WriteLine(info.LayoutEngine);
Console.WriteLine(info.LayoutEngineVersion);
Console.WriteLine(info.SecurityLevel);
 
foreach (var browserProperty in info.BrowserProperties)
{
    Console.WriteLine("{0} {1} {2}: {3}", browserProperty.Category,
        browserProperty.CategoryVersion,
        browserProperty.Capability,
        browserProperty.HasCapability);
}
 
foreach (var modelProperty in info.ModelProperties)
{
    Console.WriteLine("Model Property {0}: {1}", modelProperty.Property, modelProperty.PropertyValue);
}
Dim detectionLogic As New DetectionLogic() 'Trial Mode
'DetectionLogic detectionLogic = new DetectionLogic("place user name here", "place license key here"); //License Mode
 
'Parameters
Dim userAgent As String = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
 
Dim info As DeviceInformation = detectionLogic.DetectDevice(userAgent)
 
'Write out everything at once
Console.WriteLine(info.ToString())
 
'Write out individual properties
Console.WriteLine(info.UserAgent)
Console.WriteLine(info.EasyBrowser)
Console.WriteLine(info.EasyPlatform)
Console.WriteLine(info.BrowserType)
Console.WriteLine(info.IsTouch)
Console.WriteLine(info.BrowserName)
Console.WriteLine(info.BrowserVersion)
Console.WriteLine(info.BrandName)
Console.WriteLine(info.Identifier)
Console.WriteLine(info.ModelName)
Console.WriteLine(info.ModelNumber)
Console.WriteLine(info.OperatingSystem)
Console.WriteLine(info.OperatingSystemVersion)
Console.WriteLine(info.ProcessorType)
Console.WriteLine(info.Culture)
Console.WriteLine(info.LayoutEngine)
Console.WriteLine(info.LayoutEngineVersion)
Console.WriteLine(info.SecurityLevel)
 
For Each browserProperty In info.BrowserProperties
    Console.WriteLine("{0} {1} {2}: {3}", browserProperty.Category, browserProperty.CategoryVersion, browserProperty.Capability, browserProperty.HasCapability)
Next browserProperty
 
For Each modelProperty In info.ModelProperties
    Console.WriteLine("Model Property {0}: {1}", modelProperty.Property, modelProperty.PropertyValue)
Next modelProperty
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DetectionLogic Class
DetectionLogic Members