Skip to content

Instantly share code, notes, and snippets.

@wagonli
Last active September 10, 2019 22:32
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save wagonli/40d8a31bd0d6f0dd7a5d to your computer and use it in GitHub Desktop.
Save wagonli/40d8a31bd0d6f0dd7a5d to your computer and use it in GitHub Desktop.
Detect device type on Universal Windows Platform (UWP)
using Windows.System.Profile;
using Windows.UI.ViewManagement;
namespace Wagonli.Tools
{
public static class DeviceTypeHelper
{
public static DeviceFormFactorType GetDeviceFormFactorType()
{
switch (AnalyticsInfo.VersionInfo.DeviceFamily)
{
case "Windows.Mobile":
return DeviceFormFactorType.Phone;
case "Windows.Desktop":
return UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Mouse
? DeviceFormFactorType.Desktop
: DeviceFormFactorType.Tablet;
case "Windows.Universal":
return DeviceFormFactorType.IoT;
case "Windows.Team":
return DeviceFormFactorType.SurfaceHub;
default:
return DeviceFormFactorType.Other;
}
}
}
public enum DeviceFormFactorType
{
Phone,
Desktop,
Tablet,
IoT,
SurfaceHub,
Other
}
}
@lindexi
Copy link

lindexi commented Jun 16, 2017

Good

@DashPriyabrata
Copy link

Nicely Done! Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment