Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 709
Boris Salimov Avatar asked Oct 19 '22 21:10

Boris Salimov


1 Answers

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.

like image 73
Artemious Avatar answered Nov 16 '22 19:11

Artemious