In this example, you will see how to redirect a user to a mobile or desktop version of a site. To determine the device type, you can use the RenderUtils.Browser.Platform property. To encapsulate the process of determining the device type, create a Device class with static fields that will represent the device type, for example, isPhone, isTablet and isDesktop. Please note that in the BrowserPlatform class there is no difference between tablets and phones, so for most complex scenarios you might want to parse a user agent and make a custom determination mechanism.
The BrowserPlatform class provides you with a set of properties, which will help you determine the user’s device type:
- IsAndroidMobile - Android phones and tablets
- IsMacOS – Apple PC
- IsMacOSMobile – Apple iPhones and iPads
- IsMSTouchUI – Microsoft surface and touch monitors
- IsTouchUI – Devices with a touch interface
- IsWebKitTouchUI – Mobile browsers
- IsWindows – Microsoft Windows PC
- IsWindowsPhone – Microsoft Windows Phone OS