Skip to content

Instantly share code, notes, and snippets.

@markjulmar
Last active July 11, 2017 13:15
Show Gist options
  • Save markjulmar/ff428a370e28467989be54f19908333b to your computer and use it in GitHub Desktop.
Save markjulmar/ff428a370e28467989be54f19908333b to your computer and use it in GitHub Desktop.
Detect UWP device type
public enum DeviceType
{
Phone,
Tablet,
Desktop,
IoT,
Xbox,
SurfaceHub,
HoloLens,
Other
}
public static class DeviceDetection
{
public static DeviceType Detect()
{
switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily)
{
case "Windows.Mobile":
return DeviceType.Phone;
case "Windows.Desktop":
return DeviceType UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Mouse
? DeviceType.Desktop : DeviceType.Tablet;
break;
case "Windows.Universal":
return DeviceType.IoT;
case "Windows.Team":
return DeviceType.SurfaceHub;
case "Windows.Xbox":
return DeviceType.Xbox;
case "Windows.Holographic":
return DeviceType.HoloLens;
default:
return DeviceType.Other;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment