How to detect that WP8.1 app launched on Windows 10 Mobile?

落花浮王杯 提交于 2019-12-14 01:04:23

问题


I need to check OS version (WP 8.1 or W10) in my code of WP8.1 application. What better way to do this? May be reflection or some special API for this purpose?


回答1:


I didn't find any other way to do this, so here's my approach.

The following property IsWindows10 detects if a Windows 8.1 or Windows Phone 8.1 app is running on a Windows 10 (including Windows 10 Mobile) device.

 #region IsWindows10

    static bool? _isWindows10;
    public static bool IsWindows10 => (_isWindows10 ?? (_isWindows10 = getIsWindows10Sync())).Value;

    static bool getIsWindows10Sync()
    {
        bool hasWindows81Property = typeof(Windows.ApplicationModel.Package).GetRuntimeProperty("DisplayName") != null;
        bool hasWindowsPhone81Property = typeof(Windows.Graphics.Display.DisplayInformation).GetRuntimeProperty("RawPixelsPerViewPixel") != null;

        bool isWindows10 = hasWindows81Property && hasWindowsPhone81Property;
        return isWindows10;
    }
 #endregion

How does it work?

In Windows 8.1 the Package class has a DisplayName property, which Windows Phone 8.1 doesn't have. In Windows Phone 8.1 the DisplayInformation class has a RawPixelsPerViewPixel property, which Windows 8.1 doesn't have. Windows 10 (including Mobile) has both properties. That's how we can detect which OS the app is running on.




回答2:


Try this System.Environment.OSVersion.Version



来源:https://stackoverflow.com/questions/33840624/how-to-detect-that-wp8-1-app-launched-on-windows-10-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!