How to detect that WP8.1 is running on Windows 10 Mobile?

I need to check the OS version (WP 8.1 or W10) in my WP8.1 application code. What is the best way to do this? Maybe this is a reflection or some special API for this purpose?

+5
source share
2 answers

I have not found another way to do this, so here is my approach.

The following IsWindows10 property determines whether a Windows 8.1 or Windows Phone 8.1 application is running on a Windows 10 device (including Windows 10 Mobile).

  #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 it works?

On Windows 8.1, the Package class has a DisplayName property, which is not found on Windows Phone 8.1. On Windows Phone 8.1, the DisplayInformation class has the RawPixelsPerViewPixel property, which is not found on Windows 8.1. Windows 10 (including Mobile) has both features. This is how we can determine which OS the application is running on.

+4
source

Source: https://habr.com/ru/post/1236487/


All Articles