在 Windows 通用应用中获取 Device/OS 版本和 country/language 代码

Get Device/OS version and country/language codes in a Windows Universal app

我正在尝试在 windows 通用应用程序中获取设备信息,但我无法找到提供 os 版本、国家/地区代码和语言代码的软件包。

private void SetGeneratedFields()
    {
        _fields.objectType = "user";

        if (String.IsNullOrWhiteSpace(_fields.userID))
        {
            _fields.userID = System.Guid.NewGuid().ToString();
        }

        _fields.sessionID = System.Guid.NewGuid().ToString();

        var deviceInformation = new EasClientDeviceInformation();

        _fields.appVersion = this.GetAppVersion();
        _fields.operatingSystem = deviceInformation.OperatingSystem;
        _fields.operatingSystemVersion = "?";
        _fields.countryCode = "?";
        _fields.languageCode = "?";
        _fields.deviceType = deviceInformation.FriendlyName;
    }

    private string GetAppVersion()
    {
        string appVersion = string.Format("Version: {0}.{1}.{2}.{3}",
                Package.Current.Id.Version.Major,
                Package.Current.Id.Version.Minor,
                Package.Current.Id.Version.Build,
                Package.Current.Id.Version.Revision);
        return appVersion;
    }

无法获得 OS 版本(目前)。还有其他问题与此有关,大多数答案归结为这样一个事实,即这是有意义的,因为只有 8.1 设备 运行 Windows 运行时代码。因此,如果您在 Windows 运行时应用程序中,您会自动知道这必须是 8.1(至少 Windows Phone 是这样)。我猜微软会在 Windows 10 结束后为此添加 API 调用。

您可以这样获取语言和国家代码:

// Returns the following format: en-US
var tag = Windows.Globalization.Language.CurrentInputMethodLanguageTag;