Access Device Capabilities

You can identify the capabilities of a mobile device like any other browser’s capabilities. In fact, you use the exact same class for this purpose (HttpBrowserCapabilities). You should cast this class into a MobileCapabilities class, and query the result, as the following syntax:

((MobileCapabilities)Request.Browser).HasCapability(“GPSEnabled”, null);

Notice that the HasCapability method takes two arguments, capabilityName, which is a named stored in a dictionary, and optionalArgument, which may help the evaluation process.

You can also create your own custom capabilities. You should use the following syntax:

public static bool IsGPSEnabled (MobileCapabilities capabilities, string optArg)
{
    //Your code here.
}

Be aware of that your method must return a Boolean value, and take two arguments, a strongly typed MobileCapabilities and a string. After defining your method, you must include the following markup in your web.config:

<deviceFilters>
    <filter name=”GPSEnabled” type=”Namespace.ClassName, AssemblyName” method=”IsGPSEnabled” />
</deviceFilters>

Then you can query your device’s capabilities with the topmost code. MobileCapabilities class exposes the same strongly typed properties as the Request.Browser class. However, there is another way to enquire browser capabilities. You can also use the following syntax:

Request.Browser[“propertyNameInMachine/Web.config”];

These enquires always require string or null values, so watch out to cast them into proper format.

Further Readings
Mobile Device Capabilities

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s