コード例 #1
0
        /// <inheritdoc/>
        public bool IsInternetConnected()
        {
            ConnectivityManager connectivity = GetConnectivityManager();

            // With Build.VERSION.SdkInt < BuildVersionCodes.M we would have to use an alternative
            // way to check, but Android 6 is our min version.
            NetworkCapabilities capabilities = connectivity.GetNetworkCapabilities(connectivity.ActiveNetwork);

            return((capabilities != null) && capabilities.HasCapability(NetCapability.Internet));
        }
コード例 #2
0
        /// <inheritdoc/>
        public bool IsInternetConnected()
        {
            ConnectivityManager connectivity = GetConnectivityManager();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                NetworkCapabilities capabilities = connectivity.GetNetworkCapabilities(connectivity.ActiveNetwork);
                return((capabilities != null) && capabilities.HasCapability(NetCapability.Internet));
            }

            NetworkInfo info = connectivity.ActiveNetworkInfo;

            return((info != null) && (info.IsConnected));
        }