如何检测在 Windows 10 Mobile 上启动的 WP8.1 应用程序?

编程入门 行业动态 更新时间:2024-10-25 18:25:27
本文介绍了如何检测在 Windows 10 Mobile 上启动的 WP8.1 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要在我的 WP8.1 应用程序代码中检查操作系统版本(WP 8.1 或 W10).有什么更好的方法来做到这一点?为此目的可能是反射或一些特殊的API?

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?

推荐答案

我没有找到任何其他方法可以做到这一点,所以这是我的方法.

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

以下属性 IsWindows10 可检测 Windows 8.1 或 Windows Phone 8.1 应用是否在 Windows 10(包括 Windows 10 移动版)设备上运行.

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

它是如何工作的?

在 Windows 8.1 中,Package 类具有 Windows Phone 8.1 没有的 DisplayName 属性.在 Windows Phone 8.1 中,DisplayInformation 类具有 Windows 8.1 没有的 RawPixelsPerViewPixel 属性.Windows 10(包括移动版)具有这两个属性.这就是我们如何检测应用在哪个操作系统上运行的方法.

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.

这篇关于如何检测在 Windows 10 Mobile 上启动的 WP8.1 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 09:27:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1171523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Windows   Mobile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!