Windows 10 UWP - C#: How to check network type (EDGE/3G/LTE), not only cellular vs. WLAN? [closed]

淺唱寂寞╮ 提交于 2019-12-23 13:15:20

问题


How can I check which type of cellular connection (EDGE/3G/LTE) is used at the moment? I only know how to check if device is on cellular connection or WLAN, but I need specific type of cellular connection. Thank you!


回答1:


NetworkInformation should be available for Windows 10 (https://msdn.microsoft.com/en-us/library/windows.networking.connectivity.networkinformation.getinternetconnectionprofile.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2).

You have to adjust this code for your needs:

    /// <summary>
    ///  ("Connection Type", `0`-`3`): `0` - cellular, `1` - wifi / ethernet, `2` - inne;
    /// </summary>
    /// <returns></returns>
    public byte GetConnectionGeneration()
    {
        try
        {
            ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
            if (profile.IsWwanConnectionProfile)
            {
                WwanDataClass connectionClass = profile.WwanConnectionProfileDetails.GetCurrentDataClass();
                switch (connectionClass)
                {
                    //2G-equivalent
                    case WwanDataClass.Edge:
                    case WwanDataClass.Gprs:
                    //3G-equivalent
                    case WwanDataClass.Cdma1xEvdo:
                    case WwanDataClass.Cdma1xEvdoRevA:
                    case WwanDataClass.Cdma1xEvdoRevB:
                    case WwanDataClass.Cdma1xEvdv:
                    case WwanDataClass.Cdma1xRtt:
                    case WwanDataClass.Cdma3xRtt:
                    case WwanDataClass.CdmaUmb:
                    case WwanDataClass.Umts:
                    case WwanDataClass.Hsdpa:
                    case WwanDataClass.Hsupa:
                    //4G-equivalent
                    case WwanDataClass.LteAdvanced:
                        return 0;

                    //not connected
                    case WwanDataClass.None:
                        return 2;

                    //unknown
                    case WwanDataClass.Custom:
                    default:
                        return 2;
                }
            }
            else if (profile.IsWlanConnectionProfile)
            {
                return 1;
            }
            return 2;
        }
        catch (Exception)
        {
            return 2; //as default
        }

    }


来源:https://stackoverflow.com/questions/33539251/windows-10-uwp-c-how-to-check-network-type-edge-3g-lte-not-only-cellular

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