Ejemplo n.º 1
0
        private ConnectionProfile()
        {
            NetworkInformation.VerifyNetworkStateAccess();
            _connectivityManager = (AndroidConnectivityManager)ContextHelper.Current.GetSystemService(Context.ConnectivityService);

            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.LollipopMr1)
            {
                var activeNetwork = _connectivityManager.ActiveNetwork;
                if (activeNetwork != null)
                {
                    var netCaps = _connectivityManager.GetNetworkCapabilities(activeNetwork);
                    if (netCaps != null)
                    {
                        IsWlanConnectionProfile = netCaps.HasTransport(Android.Net.TransportType.Wifi);
                        IsWwanConnectionProfile = netCaps.HasTransport(Android.Net.TransportType.Cellular);
                    }
                }
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete
                NetworkInfo info = _connectivityManager.ActiveNetworkInfo;
                if (info?.IsConnected == true)
                {
                    IsWwanConnectionProfile = IsConnectionWwan(info.Type);
                    IsWlanConnectionProfile = IsConnectionWlan(info.Type);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }