![](/img/trans.png)
[英]How to add Google analytics to windows8 mobile application using vb.net?
[英]Get Windows version in WinRT, Windows8(10) application
这个问题很简单。
我正在使用 VB.Net 开发 Windows8.1(+10) 应用程序。
而且,我想检测操作系统版本是 8.1 还是 10。甚至不想知道 XP、7 和 8 等其他版本。
但是,不推荐使用Environment.OsVersion
,
无法访问 Windows8 APP 中的注册表(即使有可能也是政策),
无法生成自定义清单(阻止)文件来检索版本信息,
无法使用“Kernel32.dll”(策略问题)进行提取。
如何在 Windows8.1 或 Windows10 Store 应用程序中获取 Windows 版本?
谢谢。
附加:
http://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe
http://www.vbforums.com/showthread.php?776481-Get-OS-version-Windows-8-1-does-not-detect
唯一的问题是该解决方案要么基于 C++,要么不适用于 Windows 8.1(metro 应用程序)。
谢谢。
您应该做的是检查新方法是否可用。 如果它们可用,请使用它们,无论操作系统版本如何。 例子:
if (Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "TryEnterFullScreenMode"))
{
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
}
我没有找到任何其他方法来做到这一点,所以这是我的方法。 (它在 C# 中,但您可以轻松地将其转换为 Visual Basic)
以下属性IsWindows10
检测 Windows 8.1 或 Windows Phone 8.1 应用程序是否在 Windows 10(包括 Windows 10 移动版)设备上运行。
#region IsWindows10
static bool? _isWindows10;
public static bool IsWindows10 => (_isWindows10 ?? (_isWindows10 = getIsWindows10Sync())).Value;
static bool getIsWindows10Sync()
{
bool hasWindows81Property = Windows.ApplicationModel.Package.Current.GetType().GetRuntimeProperties().Any(r => r.Name == "DisplayName");
bool hasWindowsPhone81Property = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().GetType().GetRuntimeProperties().Any(r => r.Name == "RawPixelsPerViewPixel");
bool isWindows10 = hasWindows81Property && hasWindowsPhone81Property;
return isWindows10;
}
#endregion
它是如何工作的?
在 Windows 8.1 中, Package
类具有 Windows Phone 8.1 没有的DisplayName
属性。 在 Windows Phone 8.1 中, DisplayInformation
类具有 Windows 8.1 没有的RawPixelsPerViewPixel
属性。 Windows 10(包括移动版)具有这两个属性。 这就是我们如何检测应用程序正在运行的操作系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.