Skip to content

Instantly share code, notes, and snippets.

@DamienDoumer
Forked from wagonli/DeviceTypeHelper.cs
Last active January 8, 2019 14:32
Show Gist options
  • Save DamienDoumer/da7e96d0051bdc2ae5c0af3c3bd73896 to your computer and use it in GitHub Desktop.
Save DamienDoumer/da7e96d0051bdc2ae5c0af3c3bd73896 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;
case "Windows.Xbox":
return DeviceFormFactorType.Xbox;
default:
return DeviceFormFactorType.Other;
}
}
}
public enum DeviceFormFactorType
{
Phone,
Desktop,
Tablet,
IoT,
SurfaceHub,
Other,
Xbox
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment