C# 在windows universal 8.1中获取操作系统版本
我正在开发一个Windows universal 8.1应用程序。我想获得操作系统版本。在Windows10Mobile之前,我可以假设版本是8.1,但目前这个假设是不正确的。是否有办法在Windows 8.1通用应用程序中获取操作系统版本?Windows Phone 8.1 Silverlight应用程序可以使用.NET版本的API。在Universal 8.1应用程序中不支持获取版本号的机制,但您可以尝试使用反射获取Windows 10C# 在windows universal 8.1中获取操作系统版本,c#,.net,windows-phone-8.1,windows-8.1,win-universal-app,C#,.net,Windows Phone 8.1,Windows 8.1,Win Universal App,我正在开发一个Windows universal 8.1应用程序。我想获得操作系统版本。在Windows10Mobile之前,我可以假设版本是8.1,但目前这个假设是不正确的。是否有办法在Windows 8.1通用应用程序中获取操作系统版本?Windows Phone 8.1 Silverlight应用程序可以使用.NET版本的API。在Universal 8.1应用程序中不支持获取版本号的机制,但您可以尝试使用反射获取Windows 10AnalyticsInfo类,如果您在Windows 1
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);
@我明白了。但有没有办法确定设备是8.1还是10?当然,它们运行的是不同的.NET版本。如果你为8.1构建应用程序,那么它可以在8.1和10中运行;但是,如果您为10构建它,它将无法在8.1中运行。考虑到如果你为8而构建,你无法知道它是8.1还是10。1@cFrozenDeath我很奇怪为什么微软没有向开发者公开这样的Api。那么AdDuplex是如何知道操作系统版本的(我想他们有适用于windows universal的sdk)?我认为Microsoft希望您检查特定功能,而不是依赖操作系统版本。@ForguesR我需要版本,因为我的应用程序将版本发送到服务器用于统计目的