Windows 10 UWP - C #: How to check the type of network (EDGE / 3G / LTE), not just cellular or WLAN?

How can I check what type of cellular connection (EDGE / 3G / LTE) is currently in use? I only know how to check if the device is connected to a cellular connection or WLAN, but I need a specific type of cellular connection. Thanks!

+4
source share
1 answer

Network information 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 ).

:

    /// <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
        }

    }
+6

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


All Articles