如何以编程方式检测Windows Phone 8.1操作系统版本?

问题描述 投票:10回答:6

标题中的问题不是真正的问题。我浏览了许多站点和博客,并了解到Environment.OSVersion使用我们的应用程序为您提供了手机的当前操作系统版本。但是问题是,在环境类下没有OSVersion。请参考屏幕截图以更好地理解。

我的问题,为什么我不能在Environment类下看到OSVersion属性?我缺少什么吗?“在此处输入图像描述”

c# .net-4.5 windows-phone-8.1 win-universal-app
6个回答

13
投票

Universal / WinRT应用程序只能在wp 8.1中运行,因此OS版本只能为8.1。当他们制作wp8.2或wp9时,他们可能会添加一种检查安装的操作系统版本的方法...

如果您正在寻找固件版本,则可以使用:

    Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
    var firmwareVersion = deviceInfo.SystemFirmwareVersion;

12
投票

从重复的问题中复制:

Windows Phone 8.1 Silverlight应用程序可以使用.NET版本的API。在Universal 8.1应用程序中没有获得版本号的受支持机制,但是您可以尝试使用反射来获取Windows 10 AnalyticsInfo类,如果您在Windows 10上运行,它将至少告诉您版本号。

:检查操作系统版本是[[几乎总是]]错误的事情,除非您只是简单地将它显示给用户(例如,在“关于”框中)或发送给您。后端分析服务器进行数字运算。不应将其用于执行任何运行时决策,因为通常,它不是无论您实际上要尝试做什么的代理。”这里是一个示例:

var analyticsInfoType = Type.GetType( "Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime"); var versionInfoType = Type.GetType( "Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime"); if (analyticsInfoType == null || versionInfoType == null) { Debug.WriteLine("Apparently you are not on Windows 10"); return; } var versionInfoProperty = analyticsInfoType.GetRuntimeProperty("VersionInfo"); object versionInfo = versionInfoProperty.GetValue(null); var versionProperty = versionInfoType.GetRuntimeProperty("DeviceFamilyVersion"); object familyVersion = versionProperty.GetValue(versionInfo); long versionBytes; if (!long.TryParse(familyVersion.ToString(), out versionBytes)) { Debug.WriteLine("Can't parse version number"); return; } Version uapVersion = new Version((ushort)(versionBytes >> 48), (ushort)(versionBytes >> 32), (ushort)(versionBytes >> 16), (ushort)(versionBytes)); Debug.WriteLine("UAP Version is " + uapVersion);

显然,您可以对其进行更新以返回版本等,而不是将其打印到调试控制台。

[我发现了一种检测设备是否正在运行Windows Phone 8.1或Windows Phone 10的棘手方法。我比较了3种不同的设备,诺基亚Lumia 925(wp 8.1),诺基亚Lumia 735(wp 10)和诺基亚Lumia 930 (wp 10)。我注意到在wp8.1上没有设备信息ID(它会导致未实现的异常),但在两个经过测试的设备上的Windows Phone 10上都存在。另外,wp 8.1和wp 10之间的系统固件版本格式似乎有所不同(第一个是xxxx.xxxxx.xxxx.xxxx,第二个是xxxxx.xxxxx.xxxxx.xxxxx)。在我的功能下面:

/// <summary> /// Indicates if this device is running a version of Windows Phone 8.1. It use a dirty trick for detecting the OS major version /// based on the system firmware version format (8.1 is xxxx.xxxxx.xxxx.xxxx while 10 is xxxxx.xxxxx.xxxxx.xxxxx ) /// moreover, the "deviceInfo.id" is not implemented on Windows Phone 8.1, but it is on Windows Phone 10 /// </summary> /// <returns></returns> public static bool liIsWindowsPhone81(bool basedOnDeviceInfoId) { EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation(); bool isWin81 = false; if (basedOnDeviceInfoId) { try { var deviceInfoId = deviceInfo.Id; } catch { isWin81 = true; } } else { string firmwareVersion = deviceInfo.SystemFirmwareVersion.Trim(); string[] parts = firmwareVersion.Split('.'); if (parts[0].Length == 4 && parts[1].Length == 5 && parts[2].Length == 4 && parts[3].Length == 4) { isWin81 = true; } } return isWin81; }

enter image description here

我还没有机会在其他设备上对此进行测试,但到目前为止似乎还可以。我用它来区分Windows Phone 8.1和Windows Phone 10之间应用程序评级功能的代码,在我的特定情况下不是UWP

希望这会有所帮助

如果您的应用程序基于Silverlight,则可以在Windows Phone 8.0和8.1以及Windows Mobile 10上使用System.Environment.OSVersion.Version。

这是我们在确定是显示自己的“选择加入”对话框进行地理跟踪还是让Windows Mobile 10展示其自己的“选择加入”对话框时使用的方法的示例。

public static bool IsWindowsPhone8x() { try { Version version = System.Environment.OSVersion.Version; return version.Major > 8 ? false : true; } catch (Exception) { return false; } }

只需使用此行即可获取应用程序名称和ID,发布者名称等...

string name = Windows.ApplicationModel.Package.Current.DisplayName;


0
投票
[我发现了一种检测设备是否正在运行Windows Phone 8.1或Windows Phone 10的棘手方法。我比较了3种不同的设备,诺基亚Lumia 925(wp 8.1),诺基亚Lumia 735(wp 10)和诺基亚Lumia 930 (wp 10)。我注意到在wp8.1上没有设备信息ID(它会导致未实现的异常),但在两个经过测试的设备上的Windows Phone 10上都存在。另外,wp 8.1和wp 10之间的系统固件版本格式似乎有所不同(第一个是xxxx.xxxxx.xxxx.xxxx,第二个是xxxxx.xxxxx.xxxxx.xxxxx)。在我的功能下面:

0
投票
如果您的应用程序基于Silverlight,则可以在Windows Phone 8.0和8.1以及Windows Mobile 10上使用System.Environment.OSVersion.Version。

-2
投票
只需使用此行即可获取应用程序名称和ID,发布者名称等...
© www.soinside.com 2019 - 2024. All rights reserved.