本文提供一個方法,可以判斷當前的設備是PC還是手機,UWP 判斷當前的 PC 是否平板模式,判斷是否蘇非的設備
如果需要判斷 當前的設置是平板或者pc,判斷當前是否是手機,那麼可以使用下面的代碼
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 } }
參見:Detect device type on Universal Windows Platform